workflow-4-node
Version:
Workflow 4 Node is a .NET Workflow Foundation like framework for Node.js. The goal is to reach feature equivalence and beyond.
49 lines (41 loc) • 1.13 kB
JavaScript
;
let Activity = require("./activity");
let util = require("util");
let WithBody = require("./withBody");
function While() {
WithBody.call(this);
this.condition = null;
}
util.inherits(While, WithBody);
While.prototype.run = function (callContext, args) {
let condition = this.condition;
if (condition) {
callContext.schedule(condition, "_conditionGot");
}
else {
callContext.complete();
}
};
While.prototype._conditionGot = function (callContext, reason, result) {
if (reason === Activity.states.complete) {
if (!result) {
callContext.complete(this._lastBodyResult);
}
else {
WithBody.prototype.run.call(this, callContext);
}
}
else {
callContext.end(reason, result);
}
};
While.prototype.bodyCompleted = function (callContext, reason, result) {
if (reason === Activity.states.complete) {
this._lastBodyResult = result;
callContext.schedule(this.condition, "_conditionGot");
}
else {
callContext.end(reason, result);
}
};
module.exports = While;