-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
c909fcd
commit dcc2506
Showing
4 changed files
with
89 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
Event, | ||
EventTarget, | ||
AddEventListenerOptions, | ||
EventListenerOptions, | ||
EventTargetListener | ||
} from "event-target-shim"; | ||
|
||
export as namespace AbortControllerShim; | ||
|
||
export type AbortSignalListener = (this: AbortSignal, ev: any) => any; | ||
|
||
export class AbortSignal extends EventTarget { | ||
private constructor(); | ||
|
||
/** | ||
* Returns true if this AbortSignal's AbortController has signaled to abort, and false | ||
* otherwise. | ||
*/ | ||
readonly aborted: boolean; | ||
onabort: AbortSignalListener | null; | ||
addEventListener(type: "abort", listener: AbortSignalListener, options?: boolean | AddEventListenerOptions): void; | ||
addEventListener(type: string, listener: EventTargetListener | null, options?: boolean | AddEventListenerOptions): void; | ||
removeEventListener(type: "abort", listener: AbortSignalListener, options?: boolean | EventListenerOptions): void; | ||
removeEventListener(type: string, listener: EventTargetListener | null, options?: boolean | EventListenerOptions): void; | ||
} | ||
|
||
export class AbortController { | ||
/** | ||
* Returns the AbortSignal object associated with this object. | ||
*/ | ||
readonly signal: AbortSignal; | ||
|
||
/** | ||
* Invoking this method will set this object's AbortSignal's aborted flag and | ||
* signal to any observers that the associated activity is to be aborted. | ||
*/ | ||
abort(): void; | ||
} | ||
export default AbortController; |
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,30 @@ | ||
import { AbortController as AbortControllerShim, AbortSignal as AbortSignalShim } from ".."; | ||
|
||
function signalCallback(as: AbortSignal) { } | ||
function signalShimCallback(as: AbortSignalShim) { } | ||
function controllerCallback(ac: AbortController) { } | ||
function controllerShimCallback(ac: AbortControllerShim) { } | ||
function abortCallback(this: AbortSignal, ev: Event) { } | ||
|
||
const controller = new AbortController(); | ||
const controllerShim = new AbortControllerShim(); | ||
const signal = controller.signal; | ||
const signalShim = controllerShim.signal; | ||
|
||
signalCallback(signal); | ||
signalCallback(signalShim); | ||
|
||
signalShimCallback(signalShim); | ||
|
||
controllerCallback(controller); | ||
controllerCallback(controllerShim); | ||
|
||
controllerShimCallback(controllerShim); | ||
|
||
if (signalShim.aborted === false) { | ||
signalShim.addEventListener("abort", abortCallback); | ||
signalShim.removeEventListener("abort", abortCallback); | ||
signalShim.onabort = null; | ||
signalShim.onabort = abortCallback; | ||
} | ||
controllerShim.abort(); |
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,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["es2015", "dom"], | ||
"noEmit": true, | ||
"strict": true | ||
}, | ||
"files": [ | ||
"test/types.ts" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |