Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function subscribe(cancelable: Cancelable | undefined, onSignaled: () => void) {
if (!isMissing(cancelable) && !isCancelable(cancelable)) throw new TypeError("Cancelable expected: cancelable");
if (cancelable === Cancelable.canceled) return Cancelable.canceled.subscribe(onSignaled);
if (cancelable === Cancelable.none || isMissing(cancelable)) return Cancelable.none.subscribe(onSignaled);
return cancelable[Cancelable.cancelSignal]().subscribe(onSignaled);
}
export function from(resources: Iterable) {
const disposablesArray: AsyncDisposable[] = [];
for (const resource of resources) {
if (!isMissing(resource) && !AsyncDisposable.hasInstance(resource) && !Disposable.hasInstance(resource)) {
throw new TypeError("AsyncDisposable element expected: resources");
}
if (isMissing(resource)) continue;
disposablesArray.push(toAsyncDisposable(resource));
}
return create(async () => {
for (const disposable of disposablesArray) {
await disposable[AsyncDisposable.asyncDispose]();
}
});
}
export function isSignaled(cancelable: Cancelable | undefined) {
if (!isMissing(cancelable) && !isCancelable(cancelable)) throw new TypeError("Cancelable expected: cancelable");
if (cancelable === Cancelable.canceled) return true;
if (cancelable === Cancelable.none || isMissing(cancelable)) return false;
return cancelable[Cancelable.cancelSignal]().signaled;
}
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)) {
export function isSignaled(cancelable: Cancelable | undefined) {
if (!isMissing(cancelable) && !isCancelable(cancelable)) throw new TypeError("Cancelable expected: cancelable");
if (cancelable === Cancelable.canceled) return true;
if (cancelable === Cancelable.none || isMissing(cancelable)) return false;
return cancelable[Cancelable.cancelSignal]().signaled;
}
constructor(initialCount: number, maxCount?: number) {
if (isMissing(maxCount)) maxCount = MAX_INT32;
if (!isNumber(initialCount)) throw new TypeError("Number expected: initialCount.");
if (!isNumber(maxCount)) throw new TypeError("Number expected: maxCount.");
if ((initialCount |= 0) < 0) throw new RangeError("Argument out of range: initialCount.");
if ((maxCount |= 0) < 1) throw new RangeError("Argument out of range: maxCount.");
if (initialCount > maxCount) throw new RangeError("Argument out of range: initialCount.");
this._currentCount = initialCount;
this._maxCount = maxCount;
}
export function from(resources: Iterable) {
const disposablesArray: AsyncDisposable[] = [];
for (const resource of resources) {
if (!isMissing(resource) && !AsyncDisposable.hasInstance(resource) && !Disposable.hasInstance(resource)) {
throw new TypeError("AsyncDisposable element expected: resources");
}
if (isMissing(resource)) continue;
disposablesArray.push(toAsyncDisposable(resource));
}
return create(async () => {
for (const disposable of disposablesArray) {
await disposable[AsyncDisposable.asyncDispose]();
}
});
}
constructor(participantCount: number, postPhaseAction?: (barrier: AsyncBarrier) => void | PromiseLike) {
if (!isNumber(participantCount)) throw new TypeError("Number expected: participantCount.");
if ((participantCount |= 0) < 0) throw new RangeError("Argument out of range: participantCount.");
if (!isMissing(postPhaseAction) && !isFunction(postPhaseAction)) throw new TypeError("Function expected: postPhaseAction.");
this._participantCount = participantCount;
this._remainingParticipants = participantCount;
this._postPhaseAction = postPhaseAction;
}
add(count?: number): void {
if (isMissing(count)) count = 1;
if (!isNumber(count)) throw new TypeError("Number expected: count.");
if ((count |= 0) <= 0) throw new RangeError("Argument out of range: count.");
if (this._remainingCount === 0) throw new Error("The event is already signaled and cannot be incremented.");
if (this._remainingCount > 0) {
this._remainingCount += count;
}
}
function decorateMember(decorators: (PropertyDecorator | MethodDecorator)[], target: object, propertyKey: PropertyKey, descriptor?: PropertyDescriptor): PropertyDescriptor | undefined {
if (typeof propertyKey !== "symbol") propertyKey = "" + propertyKey;
for (let i = decorators.length - 1; i >= 0; i--) {
const decorator = decorators[i];
const decorated = decorator(target, propertyKey, descriptor!);
if (isDefined(decorated)) {
if (!isObject(decorated)) throw new TypeError();
descriptor = decorated;
}
}
return descriptor;
}