@@ -28,7 +28,7 @@ export class IncrementalGraph {
2828
2929 private _completedQueue : Array < IncrementalDataRecordResult > ;
3030 private _nextQueue : Array <
31- ( iterable : IteratorResult < Iterable < IncrementalDataRecordResult > > ) => void
31+ ( iterable : Iterable < IncrementalDataRecordResult > | undefined ) => void
3232 > ;
3333
3434 constructor ( ) {
@@ -70,37 +70,32 @@ export class IncrementalGraph {
7070 }
7171 }
7272
73- completedIncrementalData ( ) {
74- return {
75- [ Symbol . asyncIterator ] ( ) {
76- return this ;
77- } ,
78- next : ( ) : Promise <
79- IteratorResult < Iterable < IncrementalDataRecordResult > >
80- > => {
81- const firstResult = this . _completedQueue . shift ( ) ;
82- if ( firstResult !== undefined ) {
83- return Promise . resolve ( {
84- value : this . _yieldCurrentCompletedIncrementalData ( firstResult ) ,
85- done : false ,
86- } ) ;
87- }
88- const { promise, resolve } =
89- promiseWithResolvers <
90- IteratorResult < Iterable < IncrementalDataRecordResult > >
91- > ( ) ;
92- this . _nextQueue . push ( resolve ) ;
93- return promise ;
94- } ,
95- return : ( ) : Promise <
96- IteratorResult < Iterable < IncrementalDataRecordResult > >
97- > => {
98- for ( const resolve of this . _nextQueue ) {
99- resolve ( { value : undefined , done : true } ) ;
100- }
101- return Promise . resolve ( { value : undefined , done : true } ) ;
102- } ,
103- } ;
73+ * currentCompletedBatch ( ) : Generator < IncrementalDataRecordResult > {
74+ let completed ;
75+ while ( ( completed = this . _completedQueue . shift ( ) ) !== undefined ) {
76+ yield completed ;
77+ }
78+ if ( this . _rootNodes . size === 0 ) {
79+ for ( const resolve of this . _nextQueue ) {
80+ resolve ( undefined ) ;
81+ }
82+ }
83+ }
84+
85+ nextCompletedBatch ( ) : Promise <
86+ Iterable < IncrementalDataRecordResult > | undefined
87+ > {
88+ const { promise, resolve } = promiseWithResolvers <
89+ Iterable < IncrementalDataRecordResult > | undefined
90+ > ( ) ;
91+ this . _nextQueue . push ( resolve ) ;
92+ return promise ;
93+ }
94+
95+ abort ( ) : void {
96+ for ( const resolve of this . _nextQueue ) {
97+ resolve ( undefined ) ;
98+ }
10499 }
105100
106101 hasNext ( ) : boolean {
@@ -327,24 +322,13 @@ export class IncrementalGraph {
327322 first : IncrementalDataRecordResult ,
328323 ) : Generator < IncrementalDataRecordResult > {
329324 yield first ;
330- let completed ;
331- while ( ( completed = this . _completedQueue . shift ( ) ) !== undefined ) {
332- yield completed ;
333- }
334- if ( this . _rootNodes . size === 0 ) {
335- for ( const resolve of this . _nextQueue ) {
336- resolve ( { value : undefined , done : true } ) ;
337- }
338- }
325+ yield * this . currentCompletedBatch ( ) ;
339326 }
340327
341328 private _enqueue ( completed : IncrementalDataRecordResult ) : void {
342329 const next = this . _nextQueue . shift ( ) ;
343330 if ( next !== undefined ) {
344- next ( {
345- value : this . _yieldCurrentCompletedIncrementalData ( completed ) ,
346- done : false ,
347- } ) ;
331+ next ( this . _yieldCurrentCompletedIncrementalData ( completed ) ) ;
348332 return ;
349333 }
350334 this . _completedQueue . push ( completed ) ;
0 commit comments