Skip to content

Commit 5247edc

Browse files
committed
use event target if this is unavailable
1 parent ea9405a commit 5247edc

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/abort-signal-any/src/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ export function abortSignalAny(iterable: Iterable<AbortSignal>) {
1414

1515
// otherwise ready a controller and listen for abort signals
1616
const ctrl = new AbortController();
17-
function abort(this: AbortSignal) {
18-
ctrl.abort(
19-
// TODO: we use Object(this) because `this` is undefined for signals coming from whatwg-node (ServerAdapterRequestAbortSignal)
20-
Object(this).reason,
21-
);
17+
function abort(this: AbortSignal, event: Event) {
18+
if (this instanceof AbortSignal) {
19+
ctrl.abort(this.reason);
20+
} else {
21+
ctrl.abort((event.target as AbortSignal).reason);
22+
}
2223
// do cleanup
2324
for (const signal of signals) {
2425
signal.removeEventListener('abort', abort);

0 commit comments

Comments
 (0)