it('correctly closes the channel even if another taker is active', done => { const ch = chan(10, { transducer: compose( t.flatten(), t.take(3) ) }); const out = chan(); const ctrl = chan(); go(async () => { for (const i of [0, 1, 2, 3, 4]) { await put(ch, [i, i]); } await put(ctrl); await put(ctrl); }); go(async () => { await take(ctrl); await take(ch); const value = await take(ch); await put(out, value === CLOSED ? 'closed' : value); }); go(async () => { await take(ctrl); await take(ch); const value = await take(ch); await put(out, value === CLOSED ? 'closed' : value); }); go(async () => { const value1 = await take(out); const value2 = await take(out); expect(value1 === 'closed' || value2 === 'closed').to.be.true; expect(value1 === 'closed' && value2 === 'closed').to.be.false; done(); }); });
it('handles composed transformers', done => { const xform = compose( t.map(x => x * 3), t.filter(even), t.take(3) ); const ch = chan(10, { transducer: xform }); go(async () => { for (const i of [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]) { await put(ch, i); } }); go(async () => { expect(await take(ch)).to.equal(0); expect(await take(ch)).to.equal(6); expect(await take(ch)).to.equal(24); expect(await take(ch)).to.equal(CLOSED); done(); }); });