How to use the @esfx/internal-guards.isNumber function in @esfx/internal-guards

To help you get started, we’ve selected a few @esfx/internal-guards 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-semaphore / src / index.ts View on Github external
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;
    }
github esfx / esfx / packages / async-countdown / src / index.ts View on Github external
reset(count?: number): void {
        if (isMissing(count)) count = this._initialCount;
        if (!isNumber(count)) throw new TypeError("Number expected: count.");
        if ((count |= 0) < 0) throw new RangeError("Argument out of range: count.");

        this._remainingCount = count;
        this._initialCount = count;
        if (this._remainingCount > 0) {
            this._event.reset();
        }
        else {
            this._event.set();
        }
    }
github esfx / esfx / packages / async-semaphore / src / index.ts View on Github external
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;
    }
github esfx / esfx / packages / async-barrier / src / index.ts View on Github external
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;
    }
github esfx / esfx / packages / async-countdown / src / index.ts View on Github external
constructor(initialCount: number) {
        if (!isNumber(initialCount)) throw new TypeError("Number expected: initialCount.");
        if ((initialCount |= 0) < 0) throw new RangeError("Argument out of range: initialCount.");

        this._initialCount = initialCount;
        this._remainingCount = initialCount;
        this._event = new AsyncManualResetEvent(initialCount === 0);
    }
github esfx / esfx / packages / async-barrier / src / index.ts View on Github external
add(participantCount?: number) {
        if (isMissing(participantCount)) participantCount = 1;
        if (!isNumber(participantCount)) throw new TypeError("Number expected: participantCount.");
        if ((participantCount |= 0) <= 0) throw new RangeError("Argument out of range: participantCount.");
        if (this._isExecutingPostPhaseAction) throw new Error("This method may not be called from within the postPhaseAction.");

        this._participantCount += participantCount;
        this._remainingParticipants += participantCount;
    }
github esfx / esfx / packages / async-countdown / src / index.ts View on Github external
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;
        }
    }
github esfx / esfx / packages / async-countdown / src / index.ts View on Github external
signal(count?: number): boolean {
        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 (count > this._remainingCount) throw new Error("Invalid attempt to decrement the event's count below zero.");

        this._remainingCount -= count;
        if (this._remainingCount === 0) {
            this._event.set();
            return true;
        }

        return false;
    }
github esfx / esfx / packages / async-semaphore / src / index.ts View on Github external
release(count?: number): void {
        if (isMissing(count)) count = 1;
        if (!isNumber(count)) throw new TypeError("Number expected: count.");
        if ((count |= 0) < 1) throw new RangeError("Argument out of range: count.");
        if (this._maxCount - this._currentCount < count) throw new RangeError("Argument out of range: count.");

        while (count > 0) {
            count--;
            if (!this._waiters.resolveOne()) {
                this._currentCount++;
            }
        }
    }
}
github esfx / esfx / packages / async-barrier / src / index.ts View on Github external
remove(participantCount?: number) {
        if (isMissing(participantCount)) participantCount = 1;
        if (!isNumber(participantCount)) throw new TypeError("Number expected: participantCount.");
        if ((participantCount |= 0) <= 0) throw new RangeError("Argument out of range: participantCount.");
        if (this._participantCount < participantCount) throw new RangeError("Argument out of range: participantCount.");
        if (this._isExecutingPostPhaseAction) throw new Error("This method may not be called from within the postPhaseAction.");

        this._participantCount -= participantCount;
        this._remainingParticipants -= participantCount;
        if (this._participantCount === 0) {
            this._finishPhase();
        }
    }

@esfx/internal-guards

This package provides internal utilities for @esfx and is not intended for use in user-code.

Apache-2.0
Latest version published 2 years ago

Package Health Score

48 / 100
Full package analysis

Similar packages