@@ -318,25 +318,25 @@ export class IncrementalExecutor<
318318 ) ;
319319 }
320320
321- override cancel ( reason ?: unknown ) : void {
322- super . cancel ( reason ) ;
321+ override abort ( reason ?: unknown ) : PromiseOrValue < void > {
322+ const abortPromises : Array < Promise < unknown > > = [ ] ;
323+ const superAborted = super . abort ( reason ) ;
324+ // Executor.abort is currently synchronous
325+ invariant ( ! isPromise ( superAborted ) ) ;
323326 for ( const task of this . tasks ) {
324327 const aborted = task . computation . abort ( reason ) ;
325- /* c8 ignore start */
326- // TODO: add coverage
327328 if ( isPromise ( aborted ) ) {
328- aborted . catch ( ( ) => undefined ) ;
329+ abortPromises . push ( aborted ) ;
329330 }
330- /* c8 ignore stop */
331331 }
332332 for ( const stream of this . streams ) {
333333 const aborted = stream . queue . abort ( reason ) ;
334- /* c8 ignore start */
335- // TODO: add coverage
336334 if ( isPromise ( aborted ) ) {
337- aborted . catch ( ( ) => undefined ) ;
335+ abortPromises . push ( aborted ) ;
338336 }
339- /* c8 ignore stop */
337+ }
338+ if ( abortPromises . length > 0 ) {
339+ return Promise . allSettled ( abortPromises ) . then ( ( ) => undefined ) ;
340340 }
341341 }
342342
@@ -515,7 +515,7 @@ export class IncrementalExecutor<
515515 groupedFieldSet ,
516516 deliveryGroupMap ,
517517 ) ,
518- ( reason ) => executor . cancel ( reason ) ,
518+ ( reason ) => executor . abort ( reason ) ,
519519 ) ,
520520 } ;
521521
@@ -552,7 +552,7 @@ export class IncrementalExecutor<
552552 deliveryGroupMap ,
553553 ) ;
554554 } catch ( error ) {
555- this . cancel ( ) ;
555+ ignoreAbortCleanup ( this . abort ( ) ) ;
556556 throw error ;
557557 }
558558
@@ -561,7 +561,7 @@ export class IncrementalExecutor<
561561 ( resolved ) =>
562562 this . buildExecutionGroupResult ( deliveryGroups , path , resolved ) ,
563563 ( error : unknown ) => {
564- this . cancel ( ) ;
564+ ignoreAbortCleanup ( this . abort ( ) ) ;
565565 throw error ;
566566 } ,
567567 ) ;
@@ -600,13 +600,7 @@ export class IncrementalExecutor<
600600 const filteredTasks : Array < ExecutionGroup > = [ ] ;
601601 for ( const task of tasks ) {
602602 if ( collectedErrors . hasNulledPosition ( task . path ) ) {
603- const aborted = task . computation . abort ( cancellationReason ) ;
604- /* c8 ignore start */
605- // TODO: add coverage
606- if ( isPromise ( aborted ) ) {
607- aborted . catch ( ( ) => undefined ) ;
608- }
609- /* c8 ignore stop */
603+ ignoreAbortCleanup ( task . computation . abort ( cancellationReason ) ) ;
610604 } else {
611605 filteredTasks . push ( task ) ;
612606 }
@@ -615,13 +609,7 @@ export class IncrementalExecutor<
615609 const filteredStreams : Array < ItemStream > = [ ] ;
616610 for ( const stream of streams ) {
617611 if ( collectedErrors . hasNulledPosition ( stream . path ) ) {
618- const aborted = stream . queue . abort ( cancellationReason ) ;
619- /* c8 ignore start */
620- // TODO: add coverage
621- if ( isPromise ( aborted ) ) {
622- aborted . catch ( ( ) => undefined ) ;
623- }
624- /* c8 ignore stop */
612+ ignoreAbortCleanup ( stream . queue . abort ( cancellationReason ) ) ;
625613 } else {
626614 filteredStreams . push ( stream ) ;
627615 }
@@ -741,17 +729,29 @@ export class IncrementalExecutor<
741729 const { enableEarlyExecution } = this . validatedExecutionArgs ;
742730 const queue = new Queue < StreamItemResult > (
743731 async ( { push, stop, onStop, started } ) => {
744- const cancelStreamItems = new Set < ( reason ?: unknown ) => void > ( ) ;
732+ const abortStreamItems = new Set <
733+ ( reason ?: unknown ) => PromiseOrValue < void >
734+ > ( ) ;
745735 let finishedNormally = false ;
746736 let stopRequested = false ;
747737
748738 onStop ( ( reason ) => {
749739 stopRequested = true ;
750740 if ( ! finishedNormally ) {
751- cancelStreamItems . forEach ( ( cancelStreamItem ) =>
752- cancelStreamItem ( reason ) ,
753- ) ;
754- returnIteratorCatchingErrors ( iterator ) ;
741+ const abortPromises : Array < Promise < unknown > > = [ ] ;
742+ for ( const abortStreamItem of abortStreamItems ) {
743+ const result = abortStreamItem ( reason ) ;
744+ if ( isPromise ( result ) ) {
745+ abortPromises . push ( result ) ;
746+ }
747+ }
748+ const returned = returnIteratorCatchingErrors ( iterator ) ;
749+ if ( isPromise ( returned ) ) {
750+ abortPromises . push ( returned ) ;
751+ }
752+ if ( abortPromises . length > 0 ) {
753+ return Promise . allSettled ( abortPromises ) . then ( ( ) => undefined ) ;
754+ }
755755 }
756756 } ) ;
757757 await ( enableEarlyExecution ? Promise . resolve ( ) : started ) ;
@@ -783,7 +783,6 @@ export class IncrementalExecutor<
783783 finishedNormally = true ;
784784 const stopped = stop ( ) ;
785785 /* c8 ignore start */
786- // TODO: add coverage
787786 if ( isPromise ( stopped ) ) {
788787 stopped . catch ( ( ) => undefined ) ;
789788 }
@@ -804,11 +803,11 @@ export class IncrementalExecutor<
804803 ) ;
805804 if ( isPromise ( streamItemResult ) ) {
806805 if ( enableEarlyExecution ) {
807- const cancelStreamItem = ( reason ?: unknown ) =>
808- executor . cancel ( reason ) ;
809- cancelStreamItems . add ( cancelStreamItem ) ;
806+ const abortStreamItem = ( reason ?: unknown ) =>
807+ executor . abort ( reason ) ;
808+ abortStreamItems . add ( abortStreamItem ) ;
810809 streamItemResult = streamItemResult . finally ( ( ) => {
811- cancelStreamItems . delete ( cancelStreamItem ) ;
810+ abortStreamItems . delete ( abortStreamItem ) ;
812811 } ) ;
813812 } else {
814813 // eslint-disable-next-line no-await-in-loop
@@ -864,7 +863,7 @@ export class IncrementalExecutor<
864863 } ,
865864 )
866865 . then ( undefined , ( error : unknown ) => {
867- this . cancel ( ) ;
866+ ignoreAbortCleanup ( this . abort ( ) ) ;
868867 throw error ;
869868 } ) ;
870869 }
@@ -885,7 +884,7 @@ export class IncrementalExecutor<
885884 return this . buildStreamItemResult ( null ) ;
886885 }
887886 } catch ( error ) {
888- this . cancel ( ) ;
887+ ignoreAbortCleanup ( this . abort ( ) ) ;
889888 throw error ;
890889 }
891890
@@ -904,7 +903,7 @@ export class IncrementalExecutor<
904903 } ,
905904 )
906905 . then ( undefined , ( error : unknown ) => {
907- this . cancel ( ) ;
906+ ignoreAbortCleanup ( this . abort ( ) ) ;
908907 throw error ;
909908 } ) ;
910909 }
@@ -923,6 +922,12 @@ export class IncrementalExecutor<
923922 }
924923}
925924
925+ function ignoreAbortCleanup ( aborted : PromiseOrValue < void > ) : void {
926+ if ( isPromise ( aborted ) ) {
927+ aborted . catch ( ( ) => undefined ) ;
928+ }
929+ }
930+
926931function toNodes ( fieldDetailsList : FieldDetailsList ) : ReadonlyArray < FieldNode > {
927932 return fieldDetailsList . map ( ( fieldDetails ) => fieldDetails . node ) ;
928933}
0 commit comments