Skip to content

Commit 723ec4d

Browse files
authored
fix(abort-controller): make AbortSignal WHATWG Spec compliant (#1699)
1 parent 2cb016f commit 723ec4d

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

Diff for: packages/abort-controller/src/AbortSignal.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { AbortHandler, AbortSignal as IAbortSignal } from "@aws-sdk/types";
22

33
export class AbortSignal implements IAbortSignal {
4-
public onabort?: AbortHandler;
5-
private _aborted!: boolean;
4+
public onabort: AbortHandler | null = null;
5+
private _aborted = false;
66

77
constructor() {
88
Object.defineProperty(this, "_aborted", {
@@ -24,8 +24,8 @@ export class AbortSignal implements IAbortSignal {
2424
abort(): void {
2525
this._aborted = true;
2626
if (this.onabort) {
27-
this.onabort();
28-
this.onabort = undefined;
27+
this.onabort(this);
28+
this.onabort = null;
2929
}
3030
}
3131
}

Diff for: packages/fetch-http-handler/src/fetch-http-handler.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ describe.skip(FetchHttpHandler.name, () => {
105105
fetchHttpHandler.handle({} as any, {
106106
abortSignal: {
107107
aborted: true,
108+
onabort: null,
108109
},
109110
})
110111
).rejects.toHaveProperty("name", "AbortError");
@@ -130,6 +131,7 @@ describe.skip(FetchHttpHandler.name, () => {
130131
await fetchHttpHandler.handle({} as any, {
131132
abortSignal: {
132133
aborted: false,
134+
onabort: null,
133135
},
134136
});
135137

Diff for: packages/node-http-handler/src/node-http-handler.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ describe("NodeHttpHandler", () => {
450450
{
451451
abortSignal: {
452452
aborted: true,
453+
onabort: null,
453454
},
454455
}
455456
)

Diff for: packages/node-http-handler/src/node-http2-handler.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ describe("NodeHttp2Handler", () => {
143143
nodeH2Handler.handle(new HttpRequest(getMockReqOptions()), {
144144
abortSignal: {
145145
aborted: true,
146+
onabort: null,
146147
},
147148
})
148149
).rejects.toHaveProperty("name", "AbortError");
@@ -161,6 +162,7 @@ describe("NodeHttp2Handler", () => {
161162
nodeH2Handler.handle(new HttpRequest(getMockReqOptions()), {
162163
abortSignal: {
163164
aborted: true,
165+
onabort: null,
164166
},
165167
})
166168
).rejects.toHaveProperty("name", "AbortError");

Diff for: packages/types/src/abort.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export interface AbortHandler {
2-
(): void;
2+
(this: AbortSignal, ev: any): any;
33
}
44

55
/**
@@ -18,7 +18,7 @@ export interface AbortSignal {
1818
* A function to be invoked when the action represented by this signal has
1919
* been cancelled.
2020
*/
21-
onabort?: AbortHandler;
21+
onabort: AbortHandler | null;
2222
}
2323

2424
/**

0 commit comments

Comments
 (0)