All quizzesHard
Streams & Performance — Series 3
Preview — 3 of 10 questions
What is logged?
javascript
const { Readable, Writable } = require('node:stream');
const { pipeline } = require('node:stream/promises');
const out = [];
await pipeline(
Readable.from([1, 2, 3]),
async function* (src) {
for await (const n of src) yield n * 2;
},
new Writable({ objectMode: true, write(c, _e, cb) { out.push(c); cb(); } }),
);
console.log(out.join(','));A1,2,3
BTypeError: generator is not a stream
C2,4,6
D6 — only the final value reaches the writable.
writable.write(chunk) returns false. What should the producer do?
AStop writing and wait for the 'drain' event before resuming — the false means the internal buffer is above highWaterMark, and ignoring it grows memory without bound.
BRetry immediately in a loop until it returns true.
CNothing — false means the chunk was rejected, so resend it.
DCall end(), since the stream is full.
What is logged? (CommonJS.)
javascript
const order = [];
setTimeout(() => order.push('timeout'), 0);
process.nextTick(() => order.push('nextTick'));
Promise.resolve().then(() => order.push('promise'));
order.push('sync');
setTimeout(() => console.log(order.join(' ')), 20);Async promise nextTick timeout
BnextTick sync promise timeout
Csync timeout nextTick promise
Dsync nextTick promise timeout
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.