-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from MattiasBuelens/accept-abort-signal-polyfill
Accept polyfilled abort signals
- Loading branch information
Showing
7 changed files
with
48 additions
and
25 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* A signal object that allows you to communicate with a request and abort it if required | ||
* via its associated `AbortController` object. | ||
* | ||
* @remarks | ||
* This interface is compatible with the `AbortSignal` interface defined in TypeScript's DOM types. | ||
* It is redefined here, so it can be polyfilled without a DOM, for example with | ||
* {@link https://www.npmjs.com/package/abortcontroller-polyfill | abortcontroller-polyfill} in a Node environment. | ||
*/ | ||
export interface AbortSignal { | ||
readonly aborted: boolean; | ||
|
||
addEventListener(type: 'abort', listener: () => void): void; | ||
|
||
removeEventListener(type: 'abort', listener: () => void): void; | ||
} | ||
|
||
export function isAbortSignal(value: unknown): value is AbortSignal { | ||
if (typeof value !== 'object' || value === null) { | ||
return false; | ||
} | ||
try { | ||
return typeof (value as AbortSignal).aborted === 'boolean'; | ||
} catch { | ||
// AbortSignal.prototype.aborted throws if its brand check fails | ||
return false; | ||
} | ||
} |
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
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