UNPKG

2.24 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4 return new (P || (P = Promise))(function (resolve, reject) {
5 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8 step((generator = generator.apply(thisArg, _arguments || [])).next());
9 });
10};
11Object.defineProperty(exports, "__esModule", { value: true });
12const Operation_1 = require("./Operation");
13const OperationQueue_1 = require("./OperationQueue");
14/**
15 * @class GroupOperation
16 */
17class GroupOperation extends Operation_1.Operation {
18 constructor() {
19 super();
20 this.queue = new OperationQueue_1.OperationQueue();
21 this.operations = [];
22 }
23 /**
24 * @override
25 *
26 * @returns {Promise}
27 */
28 run() {
29 return __awaiter(this, void 0, void 0, function* () {
30 yield this.queue.addOperations(this.operations);
31 const accum = [];
32 return this.operations.reduce((accum, operation) => {
33 accum.push(operation.result);
34 return accum;
35 }, accum);
36 });
37 }
38 /**
39 * @override
40 */
41 start() {
42 const _super = Object.create(null, {
43 start: { get: () => super.start }
44 });
45 return __awaiter(this, void 0, void 0, function* () {
46 this.dependencies = [];
47 return _super.start.call(this);
48 });
49 }
50 /**
51 * @param {Operation} operation
52 */
53 addOperation(operation) {
54 this.operations.push(operation);
55 this.dependencies = [];
56 }
57 /**
58 * @param {Array.<Operation>} operations
59 */
60 addOperations(operations) {
61 this.operations = this.operations.concat(operations);
62 this.dependencies = [];
63 }
64}
65exports.GroupOperation = GroupOperation;
66//# sourceMappingURL=GroupOperation.js.map
\No newline at end of file