@@ -38,6 +38,8 @@ const requestFinalizer = new FinalizationRegistry(({ signal, abort }) => {
38
38
signal . removeEventListener ( 'abort' , abort )
39
39
} )
40
40
41
+ const dependentControllerMap = new WeakMap ( )
42
+
41
43
function buildAbort ( acRef ) {
42
44
return abort
43
45
@@ -57,6 +59,21 @@ function buildAbort (acRef) {
57
59
this . removeEventListener ( 'abort' , abort )
58
60
59
61
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
+ }
60
77
}
61
78
}
62
79
}
@@ -754,11 +771,16 @@ class Request {
754
771
if ( this . signal . aborted ) {
755
772
ac . abort ( this . signal . reason )
756
773
} 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 )
757
781
util . addAbortListener (
758
- this . signal ,
759
- ( ) => {
760
- ac . abort ( this . signal . reason )
761
- }
782
+ ac . signal ,
783
+ buildAbort ( acRef )
762
784
)
763
785
}
764
786
0 commit comments