Skip to content

Commit

Permalink
fix(abort-controller): make AbortSignal WHATWG Spec compliant (#1699)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Nov 19, 2020
1 parent 2cb016f commit 723ec4d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/abort-controller/src/AbortSignal.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AbortHandler, AbortSignal as IAbortSignal } from "@aws-sdk/types";

export class AbortSignal implements IAbortSignal {
public onabort?: AbortHandler;
private _aborted!: boolean;
public onabort: AbortHandler | null = null;
private _aborted = false;

constructor() {
Object.defineProperty(this, "_aborted", {
Expand All @@ -24,8 +24,8 @@ export class AbortSignal implements IAbortSignal {
abort(): void {
this._aborted = true;
if (this.onabort) {
this.onabort();
this.onabort = undefined;
this.onabort(this);
this.onabort = null;
}
}
}
2 changes: 2 additions & 0 deletions packages/fetch-http-handler/src/fetch-http-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ describe.skip(FetchHttpHandler.name, () => {
fetchHttpHandler.handle({} as any, {
abortSignal: {
aborted: true,
onabort: null,
},
})
).rejects.toHaveProperty("name", "AbortError");
Expand All @@ -130,6 +131,7 @@ describe.skip(FetchHttpHandler.name, () => {
await fetchHttpHandler.handle({} as any, {
abortSignal: {
aborted: false,
onabort: null,
},
});

Expand Down
1 change: 1 addition & 0 deletions packages/node-http-handler/src/node-http-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ describe("NodeHttpHandler", () => {
{
abortSignal: {
aborted: true,
onabort: null,
},
}
)
Expand Down
2 changes: 2 additions & 0 deletions packages/node-http-handler/src/node-http2-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ describe("NodeHttp2Handler", () => {
nodeH2Handler.handle(new HttpRequest(getMockReqOptions()), {
abortSignal: {
aborted: true,
onabort: null,
},
})
).rejects.toHaveProperty("name", "AbortError");
Expand All @@ -161,6 +162,7 @@ describe("NodeHttp2Handler", () => {
nodeH2Handler.handle(new HttpRequest(getMockReqOptions()), {
abortSignal: {
aborted: true,
onabort: null,
},
})
).rejects.toHaveProperty("name", "AbortError");
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/abort.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface AbortHandler {
(): void;
(this: AbortSignal, ev: any): any;
}

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

/**
Expand Down

0 comments on commit 723ec4d

Please sign in to comment.