@chix/flow
Version:
97 lines • 4.03 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var _debug = require("debug");
var common_1 = require("../common");
var events_1 = require("../events");
var util_1 = require("../util");
var control_1 = require("./control");
var export_1 = require("./export");
var nodebox_1 = require("./nodebox");
var port_1 = require("./port");
var ports_1 = require("./ports");
var runOnce_1 = require("./runOnce");
var shutdown_1 = require("./shutdown");
var debug = _debug('chix:actor');
function $Start(Base) {
return (function (_super) {
__extends(Start$, _super);
function Start$() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.active = false;
return _this;
}
Start$.prototype.start = function () {
if (['created', 'stopped'].indexOf(this.status) >= 0) {
this.setStatus('started');
debug('%s: running on start', this.identifier);
if (this.nodebox.on.start) {
var name_1 = this.ns + "_" + this.name;
if (!this._onStart) {
var onStart = this.nodebox.on.start === 'function'
? this.nodebox.on.start
: this.nodebox.on.start.toString();
this._onStart = this._createPortBox(onStart, name_1);
this._onStart.run(this);
this.nodebox.state = this.state = this._onStart.state;
}
else {
this._onStart.run(this);
}
}
this.event(events_1.NodeEvents.STARTED, {
node: this.export(),
});
this.setStatus('running');
}
else {
throw Error('Only can start node which is in the `created` or `stopped` state, current status: ' +
this.status);
}
};
Start$.prototype.__start = function (params) {
var _this = this;
if (this.active) {
debug('%s: node still active delaying', this.identifier);
this._delay = this._delay + this.interval;
setTimeout(function () {
_this.__start(params);
}, 500 + this._delay);
}
else {
this.active = true;
if (!this.async) {
if (this.nodebox.on) {
if (this.nodebox.on.shutdown) {
debug('%s: running shutdown', this.identifier);
this.shutdown();
}
}
}
this.nodebox.set('$', params);
this._runOnce();
}
};
return Start$;
}(Base));
}
exports.$Start = $Start;
(function ($Start) {
function create(Base) {
return util_1.mixin($Start, control_1.$Control.create, common_1.$Identity.create, common_1.$Event.create, export_1.$Export.create, runOnce_1.$RunOnce.create, nodebox_1.$Nodebox.create, port_1.$Port.create, ports_1.$Ports.create, common_1.$Status.create, shutdown_1.$Shutdown.create)(Base);
}
$Start.create = create;
})($Start = exports.$Start || (exports.$Start = {}));
//# sourceMappingURL=start.js.map