How to use the @esfx/cancelable.Cancelable.hasInstance function in @esfx/cancelable

To help you get started, we’ve selected a few @esfx/cancelable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github esfx / esfx / packages / async-canceltoken / src / index.ts View on Github external
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() {
github esfx / esfx / packages / async-canceltoken / src / index.ts View on Github external
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)) {
github esfx / esfx / packages / async-canceltoken / src / index.ts View on Github external
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";
            },