MCPcopy Create free account
hub / github.com/nodejs/node / testShareSyncCancelMidIteration

Function testShareSyncCancelMidIteration

test/parallel/test-stream-iter-share-sync.js:60–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

58}
59
60function testShareSyncCancelMidIteration() {
61 // Verify cancel during iteration stops data flow and cleans up
62 const enc = new TextEncoder();
63 let sourceReturnCalled = false;
64 function* gen() {
65 try {
66 yield [enc.encode('a')];
67 yield [enc.encode('b')];
68 yield [enc.encode('c')];
69 } finally {
70 sourceReturnCalled = true;
71 }
72 }
73 const shared = shareSync(gen(), { highWaterMark: 16 });
74 const consumer = shared.pull();
75
76 const items = [];
77 for (const batch of consumer) {
78 for (const chunk of batch) {
79 items.push(new TextDecoder().decode(chunk));
80 }
81 // Cancel after first batch
82 shared.cancel();
83 }
84 assert.strictEqual(items.length, 1);
85 assert.strictEqual(items[0], 'a');
86 assert.strictEqual(sourceReturnCalled, true);
87}
88
89function testShareSyncCancelWithReason() {
90 // When cancel(reason) is called, a consumer that hasn't started

Callers 1

Calls 6

shareSyncFunction · 0.85
genFunction · 0.70
decodeMethod · 0.65
pullMethod · 0.45
pushMethod · 0.45
cancelMethod · 0.45

Tested by

no test coverage detected