Skip to content

Instantly share code, notes, and snippets.

@wedneyyuri
Created January 31, 2018 16:00
Show Gist options
  • Save wedneyyuri/b5093ebbde5e423d0fae314294148e0e to your computer and use it in GitHub Desktop.
Save wedneyyuri/b5093ebbde5e423d0fae314294148e0e to your computer and use it in GitHub Desktop.
Backpressuring in Streams
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);
@wedneyyuri
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment