Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}
function isSignaled(signal: CancelSignal) {
return signal.signaled;
}
function canBeSignaled(signal: CancelSignal) {
return signal !== Cancelable.none && (!(signal instanceof CancelToken) || signal.canBeSignaled);
}
const disposablePrototype: object = Object.getPrototypeOf(Disposable.create(() => { }));
const cancelSourcePrototype: object = {
[Cancelable.cancelSignal](this: CancelSource) { return this.token; },
[CancelableSource.cancel](this: CancelSource) { this.cancel(); },
};
Object.setPrototypeOf(cancelSourcePrototype, disposablePrototype);
defineTag(cancelSourcePrototype, "CancelSource");
function createCancelSource(links: CancelLinks | undefined): CancelSource {
let state: "unsignaled" | "signaled" | "closed" = "unsignaled";
let token: CancelToken | undefined;
let subscriptions: LinkedList<() => void> | undefined;
const source: CancelSource = Object.setPrototypeOf({
get token() {
return token || (token = createCancelToken({
getState() {
return state === "unsignaled" && links ? links.getLinkedState() : state;
},
subscribe(onSignaled) {
[Cancelable.cancelSignal]: {
...methodBase,
value(this: AbortSignal) {
return getOrCreateCancelSignal(this);
}
}
});
Object.defineProperties(AbortController.prototype, {
[CancelableSource.cancelSignal]: {
...methodBase,
value(this: AbortController) {
return getOrCreateCancelSignal(this.signal);
}
},
[CancelableSource.cancel]: {
...methodBase,
value(this: AbortController) {
this.abort();
}
}
});
}