@boost/core
Version:
Robust pipeline for creating dev tools that separate logic into routines and tasks.
34 lines (33 loc) • 1.6 kB
JavaScript
;
/* eslint-disable no-restricted-syntax, no-await-in-loop */
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Executor_1 = __importDefault(require("../Executor"));
class SerialExecutor extends Executor_1.default {
/**
* Execute tasks in sequential order with the output of each
* task being passed to the next promise in the chain.
*/
run(handler, tasks, value) {
return __awaiter(this, void 0, void 0, function* () {
this.debug('Serializing %d tasks', tasks.length);
let nextValue = value;
for (const task of tasks) {
nextValue = yield handler(task, nextValue);
}
return nextValue;
});
}
}
exports.default = SerialExecutor;