UNPKG

prex-es5

Version:

Async coordination primitives and extensions on top of ES6 Promises

41 lines (39 loc) 1.34 kB
/*! ***************************************************************************** Copyright (c) Microsoft Corporation. Licensed under the Apache License, Version 2.0. See LICENSE file in the project root for details. ***************************************************************************** */ import { CancellationToken } from "./cancellation"; /** * Limits the number of asynchronous operations that can access a resource * or pool of resources. */ export declare class Semaphore { private _maxCount; private _currentCount; private _waiters; /** * Initializes a new instance of the Semaphore class. * * @param initialCount The initial number of entries. * @param maxCount The maximum number of entries. */ constructor(initialCount: number, maxCount?: number); /** * Gets the number of remaining asynchronous operations that can enter * the Semaphore. */ readonly count: number; /** * Asynchronously waits for the event to become signaled. * * @param token A CancellationToken used to cancel the request. */ wait(token?: CancellationToken): Promise<void>; /** * Releases the Semaphore one or more times. * * @param count The number of times to release the Semaphore. */ release(count?: number): void; }