Backpressure Idea Demo
NodeJS
Hard
3 views
Problem Description
Pipe a readable to writable and log when drain happens.
Output Format
Print some logs.
Constraints
Use a slow writable.
Official Solution
const { Readable, Writable } = require('stream');
const src = Readable.from(Array.from({ length: 50 }, () => 'meetcode\
'));
const sink = new Writable({
highWaterMark: 8,
write(chunk, enc, cb) {
setTimeout(cb, 5);
}
});
sink.on('drain', () => console.log('drain'));
src.pipe(sink).on('finish', () => console.log('done'));
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!