Skip to content

Commit

Permalink
docs(abort-controller): add message about browsers (#4591)
Browse files Browse the repository at this point in the history
* docs(abort-controller): add message about browsers

* docs(abort-controller): update packages/abort-controller/src/AbortController.ts

Co-authored-by: Trivikram Kamat <[email protected]>

* fix(types): global AbortController type compat

---------

Co-authored-by: Trivikram Kamat <[email protected]>
  • Loading branch information
kuhe and trivikr authored Mar 30, 2023
1 parent ed7d81e commit 324e89e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/abort-controller/src/AbortController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { AbortController as IAbortController } from "@aws-sdk/types";

import { AbortSignal } from "./AbortSignal";

/**
* This implementation was added as Node.js didn't support AbortController prior to 15.x
* Use native implementation in browsers or Node.js >=15.4.0.
*/
export class AbortController implements IAbortController {
public readonly signal: AbortSignal = new AbortSignal();

Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"build:types": "tsc -p tsconfig.types.json",
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"test": "exit 0"
"test": "tsc -p tsconfig.test.json"
},
"author": {
"name": "AWS SDK for JavaScript Team",
Expand Down
5 changes: 5 additions & 0 deletions packages/types/src/abort.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { AbortSignal } from "./abort";

// asserts that the global abortController signal is compatible with
// our signal type.
const signal: AbortSignal = new AbortController().signal;
2 changes: 1 addition & 1 deletion packages/types/src/abort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface AbortSignal {
* A function to be invoked when the action represented by this signal has
* been cancelled.
*/
onabort: AbortHandler | null;
onabort: AbortHandler | Function | null;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions packages/types/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"rootDir": "src",
"noEmit": true
},
"extends": "../../tsconfig.cjs.json",
"include": ["src/"],
"exclude": []
}

0 comments on commit 324e89e

Please sign in to comment.