UNPKG

2.31 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 * Enables multiple tasks to cooperatively work on an algorithm through
11 * multiple phases.
12 */
13export declare class Barrier {
14 private _isExecutingPostPhaseAction;
15 private _postPhaseAction;
16 private _phaseNumber;
17 private _participantCount;
18 private _remainingParticipants;
19 private _waiters;
20 /**
21 * Initializes a new instance of the Barrier class.
22 *
23 * @param participantCount The initial number of participants for the barrier.
24 * @param postPhaseAction An action to execute between each phase.
25 */
26 constructor(participantCount: number, postPhaseAction?: (barrier: Barrier) => void | PromiseLike<void>);
27 /**
28 * Gets the number of the Barrier's current phase.
29 */
30 get currentPhaseNumber(): number;
31 /**
32 * Gets the total number of participants in the barrier.
33 */
34 get participantCount(): number;
35 /**
36 * Gets the number of participants in the barrier that haven't yet signaled in the current phase.
37 */
38 get remainingParticipants(): number;
39 /**
40 * Notifies the Barrier there will be additional participants.
41 *
42 * @param participantCount The number of additional participants.
43 */
44 add(participantCount?: number): void;
45 /**
46 * Notifies the Barrier there will be fewer participants.
47 *
48 * @param participantCount The number of participants to remove.
49 */
50 remove(participantCount?: number): void;
51 /**
52 * Signals that a participant has reached the barrier and waits for all other participants
53 * to reach the barrier.
54 *
55 * @param token An optional CancellationToken used to cancel the request.
56 */
57 signalAndWait(token?: CancellationToken | Cancelable): Promise<void>;
58 private _finishPhase;
59 private _nextPhase;
60 private _resolveNextPhase;
61 private _rejectNextPhase;
62}