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

Function testShareConsumerBreak

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

Source from the content-addressed store, hash-verified

255}
256
257async function testShareConsumerBreak() {
258 // Verify that a consumer breaking mid-iteration detaches properly
259 const enc = new TextEncoder();
260 async function* gen() {
261 yield [enc.encode('a')];
262 yield [enc.encode('b')];
263 yield [enc.encode('c')];
264 }
265 const shared = share(gen(), { highWaterMark: 16 });
266 const c1 = shared.pull();
267 const c2 = shared.pull();
268
269 assert.strictEqual(shared.consumerCount, 2);
270
271 // c1 breaks after first batch
272 // eslint-disable-next-line no-unused-vars
273 for await (const _ of c1) {
274 break;
275 }
276 // c1 should be detached
277 assert.strictEqual(shared.consumerCount, 1);
278
279 // c2 should still get all data
280 const data2 = await text(c2);
281 assert.strictEqual(data2, 'abc');
282}
283
284async function testShareMultipleConsumersConcurrentPull() {
285 // Multiple consumers pulling concurrently should each receive all items

Callers 1

Calls 4

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

Tested by

no test coverage detected