-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always create abortController for each execution, listen to external …
…(passed in by client) abort signal and abort our own signal after the execution is ended. Polyfill AbortController
- Loading branch information
Showing
3 changed files
with
135 additions
and
133 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,31 @@ | ||
export interface IAbortSignal { | ||
aborted: boolean; | ||
addEventListener: (type: string, handler: () => void) => void; | ||
removeEventListener: (type: string, handler: () => void) => void; | ||
} | ||
|
||
export interface IAbortController { | ||
signal: IAbortSignal; | ||
abort: (reason?: any) => void; | ||
} | ||
|
||
/* c8 ignore start */ | ||
export const AbortController: new () => IAbortController = | ||
// eslint-disable-next-line no-undef | ||
global.AbortController || | ||
class MockAbortController implements IAbortController { | ||
private _signal: IAbortSignal = { | ||
aborted: false, | ||
addEventListener: () => null, | ||
removeEventListener: () => null, | ||
}; | ||
|
||
public get signal(): IAbortSignal { | ||
return this._signal; | ||
} | ||
|
||
public abort(): void { | ||
this._signal.aborted = true; | ||
} | ||
}; | ||
/* c8 ignore stop */ |