RubenVerborgh / AsyncIterator

An asynchronous iterator library for advanced object pipelines in JavaScript
https://rubenverborgh.github.io/AsyncIterator/docs/
Other
48 stars 7 forks source link

breaking: end on read (part 1) #45

Open jeswr opened 2 years ago

jeswr commented 2 years ago

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

coveralls commented 2 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 7cb8a1d7008a22730e78e708d86999612af8c7ce on jeswr:breaking/end-on-read-call into 7a089e36e8c33c35b27b34cd670518f2fa51acce on RubenVerborgh:main.

jeswr commented 2 years ago

@RubenVerborgh this is ready for review - apparently I don't have permissions to set you as a reviewer over here ...

RubenVerborgh commented 2 years ago

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;
        // });
jeswr commented 2 years ago

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.