Created
January 31, 2018 16:00
-
-
Save wedneyyuri/b5093ebbde5e423d0fae314294148e0e to your computer and use it in GitHub Desktop.
Backpressuring in Streams
This file contains hidden or 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
const Readable = require('stream').Readable; | |
const Writable = require('stream').Writable; | |
let counter = 0; | |
const readable = new Readable({ | |
read(size) { | |
counter++; | |
this.push(counter.toString()); | |
if (counter >= 100) { | |
this.push(null); | |
return | |
} | |
} | |
}); | |
const writable = new Writable({ | |
write(chunk, encoding, callback) { | |
console.log('==================='); | |
callback(); | |
} | |
}); | |
readable.pipe(writable); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
docs: https://nodejs.org/en/docs/guides/backpressuring-in-streams/