Skip to content

Instantly share code, notes, and snippets.

@kvasdopil
Last active February 7, 2017 13:55
Show Gist options
  • Save kvasdopil/f764628bd208bc6cf3fc761193533afa to your computer and use it in GitHub Desktop.
Save kvasdopil/f764628bd208bc6cf3fc761193533afa to your computer and use it in GitHub Desktop.
// event emitter
var waits = 0;
var done = false;
db.on('data', async data => {
waits++;
await processData(data);
waits--;
if(done)
if(waits == 0)
weAreDone();
});
db.on('end', () => done = true);
// stream
async processStream(stream)
{
while(let data = await stream.read())
{
// process data
}
}
db.on('end', () => stream.close());
await Promise.all[
processStream(db),
processStream(db),
processStream(db)
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment