Option name | Type | Description |
---|---|---|
confg | Object | configuration object |
Each time split context for current step and use it in current stage
it is differs from sequential and parallel because it is not combining, stage and not limited to any number of iteration
stage
evaluating stage
split
function that split existing stage into smalls parts, it needed
function DoWhile(config) {
var self = this;
if (!(self instanceof DoWhile)) {
throw new Error('constructor is not a function');
}
if (config && config.run instanceof Function) {
config.stage = new Stage(config.run);
delete config.run;
}
Stage.apply(self, arguments);
if (!config) {
config = {};
}
if (config instanceof Stage) {
config = {
stage: config
};
}
stage, split, reachEnd, combine
if (config.stage instanceof Stage) {
self.stage = config.stage;
} else {
if (config.stage instanceof Function) {
self.stage = new Stage(config.stage);
} else {
self.stage = new Empty();
}
}
if (config.split instanceof Function) {
self.split = config.split;
}
if (config.reachEnd instanceof Function) {
self.reachEnd = config.reachEnd;
}
self.name = config.name;
}
internal declaration fo stage
DoWhile.prototype.stage = undefined;
internal declaration fo split
DoWhile.prototype.split = function(ctx, iter) {
return ctx;
};
internal declaration fo reachEnd
DoWhile.prototype.reachEnd = function(err, ctx, iter) {
return true;
};
override of reportName
DoWhile.prototype.reportName = function() {
var self = this;
return "WHI:" + self.name;
};
override of compile
split context one by one and run each after another
DoWhile.prototype.compile = function() {
var self = this;
if (!self.name) {
self.name = self.stage.reportName();
}
var run = function(err, ctx, done) {
var iter = -1;
var next = function(err, retCtx) {
iter++;
if (self.reachEnd(err, ctx, iter)) {
done(err);
} else {
self.stage.execute(self.split(ctx, iter), next);
}
};
next();
};
self.run = run;
};
Option name | Type | Description |
---|---|---|
context | Context | evaluating context |
[callback] | Context | returning callback |
override of execute
DoWhile.prototype.execute = function(context, callback) {
var self = this;
if (!self.run) {
self.compile();
}
DoWhile.super_.prototype.execute.apply(self, arguments);
};