| 14 | |
| 15 | // Signal abort on pending write (covers wireBroadcastWriteSignal + removeAt) |
| 16 | async function testBroadcastWriteAbort() { |
| 17 | const { writer, broadcast: bc } = broadcast({ |
| 18 | highWaterMark: 1, |
| 19 | backpressure: 'block', |
| 20 | }); |
| 21 | const consumer = bc.push(); |
| 22 | |
| 23 | // Fill the buffer to capacity |
| 24 | writer.writeSync(new Uint8Array([1])); |
| 25 | |
| 26 | // Next write will block — pass a signal |
| 27 | const ac = new AbortController(); |
| 28 | const writePromise = writer.write(new Uint8Array([2]), |
| 29 | { signal: ac.signal }); |
| 30 | |
| 31 | // Abort the signal |
| 32 | ac.abort(); |
| 33 | |
| 34 | await assert.rejects(writePromise, { name: 'AbortError' }); |
| 35 | |
| 36 | // Clean up |
| 37 | writer.endSync(); |
| 38 | // Drain the consumer |
| 39 | const result = []; |
| 40 | for await (const batch of consumer) { |
| 41 | result.push(...batch); |
| 42 | } |
| 43 | assert.ok(result.length >= 1); |
| 44 | } |
| 45 | |
| 46 | // Broadcast.from with sync iterable (generator) |
| 47 | async function testBroadcastFromSyncIterable() { |