Last active
February 7, 2017 13:55
-
-
Save kvasdopil/f764628bd208bc6cf3fc761193533afa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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