Open jeswr opened 2 years ago
@RubenVerborgh this is ready for review - apparently I don't have permissions to set you as a reviewer over here ...
Copying some test code by @jeswr from #75
// TODO: Re-enable this section check for once https://github.com/RubenVerborgh/AsyncIterator/pull/45
// is merged in order to check that destruction occurs immediately rather than over several ticks
// it('should destroy when closed before being read after map', async () => {
// iterator.map(x => x).close();
// // TODO: Re-enable this same-tick check once https://github.com/RubenVerborgh/AsyncIterator/pull/45
// // is merged
// // iterator.destroyed.should.be.true;
// // Wait a tick
// await Promise.resolve();
// iterator.destroyed.should.be.true;
// console.log('b', iterator._state, iterator.open, iterator.closed, iterator.ended, iterator.destroyed)
// });
// it('should destroy when closed before being read after map then filter', async () => {
// const iter = iterator.map(x => x);
// iter.filter(x => true).close();
// // TODO: Re-enable this same-tick check once https://github.com/RubenVerborgh/AsyncIterator/pull/45
// // is merged
// // iterator.destroyed.should.be.true;
// // it.destroyed.should.be.true;
// // Wait a tick
// await Promise.resolve();
// iterator.destroyed.should.be.true;
// iter.destroyed.should.be.true;
// });
Note to self: whenever I revisit this PR, I should add some more tests, and review the code, to make sure that error
events are never emitted before the iterator is started.
resolves https://github.com/RubenVerborgh/AsyncIterator/issues/25 resolves https://github.com/RubenVerborgh/AsyncIterator/issues/35
Part of https://github.com/RubenVerborgh/AsyncIterator/pull/43 without any lint or limit changes