@@ -1740,24 +1740,21 @@ export class UnionIterator<T> extends AsyncIterator<T> {
17401740 if ( iterator . readable && ( item = iterator . read ( ) ) !== null )
17411741 return item ;
17421742
1743- // If the iterator is done, get rid of it from the circular list
1744- if ( iterator . done )
1745- this . _removeSource ( iterator ) ;
1746- else
1747- this . _node = this . _node ! . next ;
1743+ // TODO: in #45 - if the iterator is done, get rid of it from the circular list
1744+ // if (iterator.done)
1745+ // this._removeSource(iterator);
1746+ // else
1747+ this . _node = this . _node ! . next ;
17481748
17491749 _size -- ;
1750- // TODO: See if this should be an else
17511750 }
17521751
17531752 while ( this . _size < this . _maxParallelIterators && ( iterator = _sources . read ( ) ) !== null ) {
1754- // TODO - it would be nice to skip adding sources if it is a single or no
1755- // element iterator.
1756- // if (!iterator.done) {
1753+ if ( ! iterator . done ) {
17571754 this . _addSource ( iterator ) ;
1758- if ( ( item = iterator . read ( ) ) !== null )
1755+ if ( iterator . readable && ( item = iterator . read ( ) ) !== null )
17591756 return item ;
1760- // }
1757+ }
17611758 }
17621759
17631760 if ( this . _size === 0 && this . _sources . done )
@@ -1794,23 +1791,31 @@ function destinationRemoveEmptySources<T>(this: InternalSource<T>) {
17941791 const destination = this [ DESTINATION ] as any ;
17951792 if ( NODE in this ) {
17961793 destination . _removeSource ( this ) ;
1797- if ( destination . _size === 0 && destination . _sources . done && destination . _sourceStarted )
1794+ if ( destination . _size === 0 && destination . _sources . done && destination . _sourceStarted ) {
17981795 destination ! . close ( ) ;
1799- // Also capture the case where we need to just start re-filling the circular
1800-
1801- // else if (destination._size < destination._maxParallelIterators && destination._sources.readable) {
1802- // TODO: Add a test case for this
1803- if ( this . readable )
1804- this . emit ( 'readable' )
1805- else
1806- this . readable = true ;
1807- // TODO: Future performance improvement - continue re-filling the circular linked list
1796+ return ;
1797+ }
1798+ destination . readable = true ;
1799+ // const _sources = destination._sources;
1800+ // let iterator;
1801+ // while (destination._size < destination._maxParallelIterators && iterator.readable && (iterator = _sources.read()) !== null) {
1802+ // if (!iterator.done) {
1803+ // destination._addSource(iterator);
1804+ // if (iterator.readable) {
1805+ // destination.readable = true;
1806+ // return;
1807+ // }
1808+ // }
18081809 // }
18091810 }
18101811 else {
18111812 destination . _unListenSource ( this ) ;
1812- if ( destination . _size === 0 && destination . _sourceStarted )
1813- destination ! . close ( ) ;
1813+ if ( destination . _size === 0 ) {
1814+ if ( destination . _sourceStarted )
1815+ destination . close ( ) ;
1816+ else
1817+ destination . readable = true ;
1818+ }
18141819 }
18151820}
18161821
0 commit comments