MCPcopy Index your code
hub / github.com/nodejs/node / testShareLateJoiningConsumer

Function testShareLateJoiningConsumer

test/parallel/test-stream-iter-share-async.js:234–255  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

232}
233
234async function testShareLateJoiningConsumer() {
235 // A consumer that joins after some data has been consumed should only
236 // see data remaining in the buffer (not items already trimmed).
237 const enc = new TextEncoder();
238 async function* gen() {
239 yield [enc.encode('a')];
240 yield [enc.encode('b')];
241 yield [enc.encode('c')];
242 }
243 const shared = share(gen(), { highWaterMark: 16 });
244
245 // First consumer reads all data
246 const c1 = shared.pull();
247 const data1 = await text(c1);
248 assert.strictEqual(data1, 'abc');
249
250 // Late-joining consumer: source is exhausted, buffer has been trimmed
251 // past all data by c1's reads, so c2 gets nothing.
252 const c2 = shared.pull();
253 const data2 = await text(c2);
254 assert.strictEqual(data2, '');
255}
256
257async function testShareConsumerBreak() {
258 // Verify that a consumer breaking mid-iteration detaches properly

Callers 1

Calls 4

shareFunction · 0.85
genFunction · 0.70
textFunction · 0.50
pullMethod · 0.45

Tested by

no test coverage detected