@@ -38,6 +38,8 @@ const requestFinalizer = new FinalizationRegistry(({ signal, abort }) => {
3838 signal . removeEventListener ( 'abort' , abort )
3939} )
4040
41+ const dependentControllerMap = new WeakMap ( )
42+
4143function buildAbort ( acRef ) {
4244 return abort
4345
@@ -57,6 +59,21 @@ function buildAbort (acRef) {
5759 this . removeEventListener ( 'abort' , abort )
5860
5961 ac . abort ( this . reason )
62+
63+ const controllerList = dependentControllerMap . get ( ac . signal )
64+
65+ if ( controllerList !== undefined ) {
66+ if ( controllerList . size !== 0 ) {
67+ for ( const ref of controllerList ) {
68+ const ctrl = ref . deref ( )
69+ if ( ctrl !== undefined ) {
70+ ctrl . abort ( this . reason )
71+ }
72+ }
73+ controllerList . clear ( )
74+ }
75+ dependentControllerMap . delete ( ac . signal )
76+ }
6077 }
6178 }
6279}
@@ -754,11 +771,16 @@ class Request {
754771 if ( this . signal . aborted ) {
755772 ac . abort ( this . signal . reason )
756773 } else {
774+ let list = dependentControllerMap . get ( this . signal )
775+ if ( list === undefined ) {
776+ list = new Set ( )
777+ dependentControllerMap . set ( this . signal , list )
778+ }
779+ const acRef = new WeakRef ( ac )
780+ list . add ( acRef )
757781 util . addAbortListener (
758- this . signal ,
759- ( ) => {
760- ac . abort ( this . signal . reason )
761- }
782+ ac . signal ,
783+ buildAbort ( acRef )
762784 )
763785 }
764786
0 commit comments