UNPKG

1.43 kBTypeScriptView Raw
1/*! *****************************************************************************
2Copyright (c) Microsoft Corporation.
3Licensed under the Apache License, Version 2.0.
4
5See LICENSE file in the project root for details.
6***************************************************************************** */
7import { CancellationToken } from "./cancellation";
8import { Cancelable } from "@esfx/cancelable";
9/**
10 * Limits the number of asynchronous operations that can access a resource
11 * or pool of resources.
12 */
13export declare class Semaphore {
14 private _maxCount;
15 private _currentCount;
16 private _waiters;
17 /**
18 * Initializes a new instance of the Semaphore class.
19 *
20 * @param initialCount The initial number of entries.
21 * @param maxCount The maximum number of entries.
22 */
23 constructor(initialCount: number, maxCount?: number);
24 /**
25 * Gets the number of remaining asynchronous operations that can enter
26 * the Semaphore.
27 */
28 get count(): number;
29 /**
30 * Asynchronously waits for the event to become signaled.
31 *
32 * @param token A CancellationToken used to cancel the request.
33 */
34 wait(token?: CancellationToken | Cancelable): Promise<void>;
35 /**
36 * Releases the Semaphore one or more times.
37 *
38 * @param count The number of times to release the Semaphore.
39 */
40 release(count?: number): void;
41}