Consider the following:
var asyncFunction = function(data, callback) {
doAsyncyThing(function(data){
// do some stuff
return callback(err)
})
}
fs.createReadStream('eupmc_lite_metadata_2016_04_15.json')
.pipe(JSONstream.parse())
.on('data', asyncFunction) // <- how to let asyncFunction complete before continuing
How does the stream know when asyncFunction has completed? Is there any way to use asynchronous functions from within streams?
on('data', asyncFunction)
cannot deal with callbacks, sinceasyncFunction
must be in the formfunction(data)
. My point is: "how then do you deal with callbacks?" – Mossberg