| 18 | // ============================================================================= |
| 19 | |
| 20 | async function testMergeTwoSources() { |
| 21 | const { writer: w1, readable: r1 } = push(); |
| 22 | const { writer: w2, readable: r2 } = push(); |
| 23 | |
| 24 | w1.write('from-a'); |
| 25 | w1.end(); |
| 26 | w2.write('from-b'); |
| 27 | w2.end(); |
| 28 | |
| 29 | const merged = merge(r1, r2); |
| 30 | const chunks = []; |
| 31 | for await (const batch of merged) { |
| 32 | for (const chunk of batch) { |
| 33 | chunks.push(new TextDecoder().decode(chunk)); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | // Both sources should be present (order is temporal, not guaranteed) |
| 38 | assert.strictEqual(chunks.length, 2); |
| 39 | assert.ok(chunks.includes('from-a')); |
| 40 | assert.ok(chunks.includes('from-b')); |
| 41 | } |
| 42 | |
| 43 | async function testMergeSingleSource() { |
| 44 | const data = await text(merge(from('only-one'))); |