-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This method takes a list of AbortSignals and returns an AbortSignal that is aborted when any of the input signals is aborted.
- Loading branch information
1 parent
9eaae99
commit 7625d8a
Showing
5 changed files
with
198 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Signal 0 aborted: false | ||
Signal 1 aborted: false | ||
Signal 2 aborted: false | ||
Signal 3 aborted: false | ||
Signal 4 aborted: false | ||
Abort callback for signal: 0. Reason: Test AbortController 1 | ||
Abort callback for signal: 1. Reason: Test AbortController 1 | ||
Abort callback for signal: 3. Reason: Test AbortController 1 | ||
Abort callback for signal: 4. Reason: Test AbortController 1 | ||
Signal 0 aborted: true | ||
Signal 1 aborted: true | ||
Signal 2 aborted: false | ||
Signal 3 aborted: true | ||
Signal 4 aborted: true | ||
Signal 0 aborted: false | ||
Signal 1 aborted: false | ||
Signal 2 aborted: false | ||
Signal 3 aborted: false | ||
Signal 4 aborted: false | ||
Abort callback for signal: 1. Reason: Test AbortController 2 | ||
Abort callback for signal: 2. Reason: Test AbortController 2 | ||
Abort callback for signal: 3. Reason: Test AbortController 2 | ||
Abort callback for signal: 4. Reason: Test AbortController 2 | ||
Signal 0 aborted: false | ||
Signal 1 aborted: true | ||
Signal 2 aborted: true | ||
Signal 3 aborted: true | ||
Signal 4 aborted: true | ||
Signal 0 aborted: false | ||
Signal 1 aborted: false | ||
Signal 2 aborted: false | ||
Signal 3 aborted: false | ||
Signal 4 aborted: false | ||
Abort callback for signal: 4. Reason: Test AbortController 3 | ||
Signal 0 aborted: false | ||
Signal 1 aborted: false | ||
Signal 2 aborted: false | ||
Signal 3 aborted: false | ||
Signal 4 aborted: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<script src="include.js"></script> | ||
<script> | ||
test(() => { | ||
function make_callback(signal, signal_number) { | ||
return () => println(`Abort callback for signal: ${signal_number}. Reason: ${signal.reason}`); | ||
} | ||
|
||
function make_signal_list() { | ||
const controller1 = new AbortController(); | ||
const controller2 = new AbortController(); | ||
const controller3 = new AbortController(); | ||
|
||
let signals = []; | ||
signals.push(AbortSignal.any([controller1.signal])); | ||
signals.push(AbortSignal.any([controller1.signal, controller2.signal])); | ||
signals.push(AbortSignal.any([controller2.signal])); | ||
signals.push(AbortSignal.any([controller2.signal, controller1.signal])); | ||
|
||
const nestedSignal = AbortSignal.any([...signals, controller3.signal]); | ||
signals.push(nestedSignal); | ||
|
||
for (let i = 0; i < signals.length; i++) { | ||
const signal = signals[i]; | ||
signal.onabort = make_callback(signal, i); | ||
} | ||
|
||
return { controllers: [controller1, controller2, controller3], signals: signals}; | ||
} | ||
|
||
function print_aborted_signals(signals) { | ||
for (let i = 0; i < signals.length; i++) { | ||
const signal = signals[i]; | ||
println(`Signal ${i} aborted: ${signal.aborted}`); | ||
} | ||
} | ||
|
||
const signal_list1 = make_signal_list(); | ||
print_aborted_signals(signal_list1.signals); | ||
signal_list1.controllers[0].abort("Test AbortController 1"); | ||
print_aborted_signals(signal_list1.signals); | ||
|
||
const signal_list2 = make_signal_list(); | ||
print_aborted_signals(signal_list2.signals); | ||
signal_list2.controllers[1].abort("Test AbortController 2"); | ||
print_aborted_signals(signal_list2.signals); | ||
|
||
const signal_list3 = make_signal_list(); | ||
print_aborted_signals(signal_list3.signals); | ||
signal_list3.controllers[2].abort("Test AbortController 3"); | ||
print_aborted_signals(signal_list3.signals); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters