Nodash.each(function (result) {
delete result.toGo;
}, results);
callback(null, results);
} else {
Nodash.each(function (_, next) {
delete depends[next][taskName];
if (Nodash.isEmpty(depends[next])) {
execute(next);
}
}, tasks[taskName].enables);
}
};
}
function execute(taskName) {
var task = tasks[taskName],
callback = callbackHandle(taskName),
dependenciesFailed = false,
args = Nodash.map(function (dependency) {
if (results[dependency].error) {
dependenciesFailed = true;
}
return results[dependency].result;
}, task.args);
if (dependenciesFailed && Nodash.isFunction(task.func.runOnError)) {
var tempResult = {};
Nodash.each(function (dependency) {
var result = results[dependency];
var stubResult = {};
if (result.error) {
stubResult.error = result.error;
} else {
stubResult.result = result.result;
}
tempResult[dependency] = stubResult;
}, task.args);
tempResult = task.func.runOnError(tempResult) || tempResult;
args = Nodash.map(function (dependency) {
return tempResult[dependency].result;
}, task.args);
}
args.push(callback);
setImmediate(function _executeTask() {
if (dependenciesFailed && !task.func.runOnError) {
callback({ message: 'dependencies failed' });
} else {
var f = task.func;
if (Nodash.isObject(f)) {
f = f.func;
}
try {
f.apply(null, args);
} catch (e) {
callback(e);
}
}
});
}
Nodash.each(function (task, taskName) {
depends[taskName] = Nodash.clone(task.depends);
}, tasks);
Nodash.each(execute, initial);
};
},
until: function (p, f, v) {
while (!p(v)) {
v = f(v);
}
return v;
},
pipe: function () {
var functions, intermediateResult, callback;
var error = null;
if (Nodash.isArray(arguments[0])) {
functions = arguments[0];
callback = arguments[1];
} else {
functions = arguments;
}
if (functions.length > 0) {
if (Nodash.isFunction(functions[0])) {
intermediateResult = functions[0]();
} else {
intermediateResult = functions[0];
}
for (var i = 1; i < functions.length; i += 1) {
try {
intermediateResult = functions[i](intermediateResult);
} catch (err) {
error = err;
}
}
}
if (Nodash.isFunction(callback)) {
callback(error, intermediateResult);
} else if (error) {
throw error;
}
return intermediateResult;
}
};
};