Meteor code inside streams

I am facing some trouble to use Meteor code inside of a stream.

Usually I would just use Future / wait, and pull all the info in need from the stream back into the “main level” and just code normally in there like this.

Future = Meteor.npmRequire('fibers/future')
Readdirp = Meteor.npmRequire('readdirp') // Recursive read dir

console.log("reading files in", dir)

const files = []
const future = new Future ()

const files_stream = Readdirp ({ root : "\tmp", entryType : 'files' })
files_stream.on('data', function (info) { files.push({ name :, file : info.fullPath }) })
files_stream.on('end', function () { future['return']() })

console.log(files.length, "files to be processed")

But in this case I need the stream to check data from a meteor collection and act accordingly. The library I am using has an option to specify a filter function

// ERROR : Can't run without a fiber      
const files_stream = Readdirp ({ 
  root : "\tmp", 
  entryType : 'files', 
  fileFilter : info => FilesAlreadyRead.findOne( 

I thought about moving the filter to the ‘data’ event manager but I don’t know what code to add there to get the collection to run on the “main level”

// ERROR : Can't run without a fiber
files_stream.on('data', function (info) {
  if (!FilesAlreadyRead.findOne( files.push({ name :, file : info.fullPath })

The answer is bindEnvironment but it doesn’t work very well in this case

Today await and promises make the interaction between Meteor (code in fibers) and Node asynchronous code completely transparent. bindEnvironment is not needed anymore and the code is faster and more readable.