1 | "use strict";
|
2 | var __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 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | const Operation_1 = require("./Operation");
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | class BlockOperation extends Operation_1.Operation {
|
18 | constructor() {
|
19 | let id;
|
20 | let block;
|
21 | const first = arguments[0];
|
22 | if (typeof first === 'number') {
|
23 | id = first;
|
24 | const second = arguments[1];
|
25 | if (typeof second === 'function') {
|
26 | block = second;
|
27 | }
|
28 | }
|
29 | else if (typeof first === 'function') {
|
30 | block = first;
|
31 | }
|
32 | else {
|
33 | throw new Error('Wrong arguments passed: missing ID and/or function');
|
34 | }
|
35 | super(id);
|
36 | this.blocks = [block];
|
37 | }
|
38 | |
39 |
|
40 |
|
41 | run() {
|
42 | return __awaiter(this, void 0, void 0, function* () {
|
43 | const promises = [];
|
44 | this.blocks.forEach(block => {
|
45 | promises.push(block(this));
|
46 | });
|
47 | const results = yield Promise.all(promises);
|
48 | return results.length === 1
|
49 | ? results[0]
|
50 | : results;
|
51 | });
|
52 | }
|
53 | |
54 |
|
55 |
|
56 |
|
57 | addBlock(block) {
|
58 | this.blocks.push(block);
|
59 | }
|
60 | }
|
61 | exports.BlockOperation = BlockOperation;
|
62 |
|
\ | No newline at end of file |