| 24 | } |
| 25 | |
| 26 | async function testShareMultipleConsumers() { |
| 27 | async function* gen() { |
| 28 | yield [new TextEncoder().encode('chunk1')]; |
| 29 | yield [new TextEncoder().encode('chunk2')]; |
| 30 | yield [new TextEncoder().encode('chunk3')]; |
| 31 | } |
| 32 | |
| 33 | const shared = share(gen(), { highWaterMark: 16 }); |
| 34 | |
| 35 | const c1 = shared.pull(); |
| 36 | const c2 = shared.pull(); |
| 37 | |
| 38 | assert.strictEqual(shared.consumerCount, 2); |
| 39 | |
| 40 | const [data1, data2] = await Promise.all([ |
| 41 | text(c1), |
| 42 | text(c2), |
| 43 | ]); |
| 44 | |
| 45 | assert.strictEqual(data1, 'chunk1chunk2chunk3'); |
| 46 | assert.strictEqual(data2, 'chunk1chunk2chunk3'); |
| 47 | } |
| 48 | |
| 49 | async function testShareConsumerCount() { |
| 50 | const shared = share(from('data')); |