Skip to content

Commit 0495b04

Browse files
committed
Add test for backpressure
1 parent 1f85e77 commit 0495b04

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/values.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,4 +602,25 @@ describe('bufferedAsyncMap() values', () => {
602602
await clock.runAllAsync();
603603
await promisedResult;
604604
});
605+
606+
it('should give back pressure', async () => {
607+
baseAsyncIterable = yieldValuesOverTime(100, (i) => i % 2 === 1 ? 2000 : 100);
608+
const baseAsyncIterator = baseAsyncIterable[Symbol.asyncIterator]();
609+
610+
const nextSpy = sinon.spy(baseAsyncIterator, 'next');
611+
612+
const asyncIterator = bufferedAsyncMap(
613+
baseAsyncIterable,
614+
async (item) => item,
615+
{ bufferSize: 10 }
616+
);
617+
618+
await clock.runAllAsync();
619+
nextSpy.should.have.callCount(10);
620+
621+
await asyncIterator.next().should.eventually.be.an('object').with.property('value').that.is.a('number');
622+
623+
await clock.runAllAsync();
624+
nextSpy.should.have.callCount(11);
625+
});
605626
});

0 commit comments

Comments
 (0)