UNPKG

@rushstack/operation-graph

Version:

Library for managing and executing operations in a directed acyclic graph.

66 lines 2.39 kB
"use strict"; // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. Object.defineProperty(exports, "__esModule", { value: true }); exports.OperationGroupRecord = void 0; const node_core_library_1 = require("@rushstack/node-core-library"); const OperationStatus_1 = require("./OperationStatus"); const Stopwatch_1 = require("./Stopwatch"); /** * Meta-entity that tracks information about a group of related operations. * * @beta */ class OperationGroupRecord { get duration() { return this._groupStopwatch ? this._groupStopwatch.duration : 0; } get finished() { return this._remainingOperations.size === 0; } get hasCancellations() { return this._hasCancellations; } get hasFailures() { return this._hasFailures; } constructor(name, metadata = {}) { this._operations = new Set(); this._remainingOperations = new Set(); this._groupStopwatch = new Stopwatch_1.Stopwatch(); this._hasCancellations = false; this._hasFailures = false; this.name = name; this.metadata = metadata; } addOperation(operation) { this._operations.add(operation); } startTimer() { // Keep this undefined until needed, then start to avoid subsequent calls to startTimer() this._groupStopwatch.start(); } setOperationAsComplete(operation, state) { if (!this._remainingOperations.has(operation)) { throw new node_core_library_1.InternalError(`Operation ${operation.name} is not in the group ${this.name}`); } if (state.status === OperationStatus_1.OperationStatus.Aborted) { this._hasCancellations = true; } else if (state.status === OperationStatus_1.OperationStatus.Failure) { this._hasFailures = true; } this._remainingOperations.delete(operation); if (this._remainingOperations.size === 0) { this._groupStopwatch.stop(); } } reset() { this._remainingOperations = new Set(this._operations); this._groupStopwatch.reset(); this._hasCancellations = false; this._hasFailures = false; } } exports.OperationGroupRecord = OperationGroupRecord; //# sourceMappingURL=OperationGroupRecord.js.map