@tripod311/leg5
Version:
Zero-dependency concurrent function execution for Node.js using worker threads.
54 lines (53 loc) • 1.3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tools_1 = require("./tools");
class Task {
constructor(name, script, argsList, args, timeout) {
this._canceled = false;
this._name = name;
this._script = script;
this._argsList = argsList;
this._args = args;
this._timeout = timeout;
this._promise = (0, tools_1.create_deferred_promise)();
}
get name() {
return this._name;
}
get script() {
return this._script;
}
get argsList() {
return this._argsList;
}
get timeout() {
return this._timeout;
}
get args() {
return this._args;
}
get promise() {
return this._promise.promise;
}
get canceled() {
return this._canceled;
}
assign(cancelFunction) {
this._cancelFunction = cancelFunction;
}
cancel() {
if (!this._canceled) {
this._canceled = true;
if (this._cancelFunction)
this._cancelFunction();
this._promise.reject(new Error("Canceled"));
}
}
finish(result) {
this._promise.resolve(result);
}
fail(reason) {
this._promise.reject(reason);
}
}
exports.default = Task;