Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static race(cancelables: Iterable) {
if (!isIterable(cancelables)) {
throw new TypeError("Object not iterable: cancelables");
}
const signals: CancelSignal[] = [];
for (const cancelable of cancelables) {
if (!Cancelable.hasInstance(cancelable)) throw new TypeError("Cancelable element expected: cancelables");
signals.push(cancelable[Cancelable.cancelSignal]());
}
if (!signals.some(canBeSignaled)) {
return CancelToken.none;
}
if (signals.some(isSignaled)) {
return CancelToken.canceled;
}
const subscriptions: CancelSubscription[] = [];
const source = createCancelSource({
getLinkedState() {
if (signals.some(isSignaled)) return "signaled";
if (signals.every(canBeSignaled)) return "unsignaled";
return "closed";
},
unlink() {
static from(cancelable: Cancelable | null | undefined) {
if (!isMissing(cancelable) && !Cancelable.hasInstance(cancelable)) {
throw new TypeError("Cancelable exepected: cancelable");
}
if (cancelable === Cancelable.none || isMissing(cancelable)) {
return CancelToken.none;
}
if (cancelable === Cancelable.canceled) {
return CancelToken.canceled;
}
if (cancelable instanceof CancelToken) {
return cancelable;
}
if (cancelSourcePrototype.isPrototypeOf(cancelable)) {
return (cancelable as CancelSource).token;
}
const signal = cancelable[Cancelable.cancelSignal]();
if (!canBeSignaled(signal)) {
static all(cancelables: Iterable) {
if (!isIterable(cancelables)) {
throw new TypeError("Object not iterable: cancelables");
}
const signals: CancelSignal[] = [];
for (const cancelable of cancelables) {
if (!Cancelable.hasInstance(cancelable)) throw new TypeError("Cancelable element expected: cancelables");
signals.push(cancelable[Cancelable.cancelSignal]());
}
if (!signals.some(canBeSignaled)) {
return CancelToken.none;
}
if (signals.every(isSignaled)) {
return CancelToken.canceled;
}
let signalsRemaining = signals.length;
const subscriptions: CancelSubscription[] = [];
const source = createCancelSource({
getLinkedState() {
if (signals.every(isSignaled)) return "signaled";
if (signals.every(canBeSignaled)) return "unsignaled";
return "closed";
},