UNPKG

prex-es5

Version:

Async coordination primitives and extensions on top of ES6 Promises

62 lines (60 loc) 2.2 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"; /** * Enables multiple tasks to cooperatively work on an algorithm through * multiple phases. */ export declare class Barrier { private _isExecutingPostPhaseAction; private _postPhaseAction; private _phaseNumber; private _participantCount; private _remainingParticipants; private _waiters; /** * Initializes a new instance of the Barrier class. * * @param participantCount The initial number of participants for the barrier. * @param postPhaseAction An action to execute between each phase. */ constructor(participantCount: number, postPhaseAction?: (barrier: Barrier) => void | PromiseLike<void>); /** * Gets the number of the Barrier's current phase. */ readonly currentPhaseNumber: number; /** * Gets the total number of participants in the barrier. */ readonly participantCount: number; /** * Gets the number of participants in the barrier that haven't yet signaled in the current phase. */ readonly remainingParticipants: number; /** * Notifies the Barrier there will be additional participants. * * @param participantCount The number of additional participants. */ add(participantCount?: number): void; /** * Notifies the Barrier there will be fewer participants. * * @param participantCount The number of participants to remove. */ remove(participantCount?: number): void; /** * Signals that a participant has reached the barrier and waits for all other participants * to reach the barrier. * * @param token An optional CancellationToken used to cancel the request. */ signalAndWait(token?: CancellationToken): Promise<void>; private _finishPhase; private _nextPhase; private _resolveNextPhase; private _rejectNextPhase; }