Better formatting

pull/2/head
Louis Chatriot 9 years ago
parent cada7ff179
commit be83e8d4ee
  1. 24
      lib/executor.js

@ -11,17 +11,16 @@ function Executor () {
// This queue will execute all commands, one-by-one in order
this.queue = async.queue(function (task, cb) {
var callback
, lastArg = task.arguments[task.arguments.length - 1]
, i, newArguments = []
;
var newArguments = [];
// task.arguments is an array-like object on which adding a new field doesn't work, so we transform it into a real array
for (i = 0; i < task.arguments.length; i += 1) { newArguments.push(task.arguments[i]); }
for (var i = 0; i < task.arguments.length; i += 1) { newArguments.push(task.arguments[i]); }
var lastArg = task.arguments[task.arguments.length - 1];
// Always tell the queue task is complete. Execute callback if any was given.
if (typeof lastArg === 'function') {
callback = function () {
// Callback was supplied
newArguments[newArguments.length - 1] = function () {
if (typeof setImmediate === 'function') {
setImmediate(cb);
} else {
@ -29,14 +28,12 @@ function Executor () {
}
lastArg.apply(null, arguments);
};
newArguments[newArguments.length - 1] = callback;
} else if (!lastArg && task.arguments.length) {
callback = function () { cb(); };
newArguments[newArguments.length - 1] = callback;
// false/undefined/null supplied as callbback
newArguments[newArguments.length - 1] = function () { cb(); };
} else {
callback = function () { cb(); };
newArguments.push(callback);
// Nothing supplied as callback
newArguments.push(function () { cb(); });
}
@ -51,7 +48,8 @@ function Executor () {
* @param {Object} task
* task.this - Object to use as this
* task.fn - Function to execute
* task.arguments - Array of arguments
* task.arguments - Array of arguments, IMPORTANT: only the last argument may be a function (the callback)
* and the last argument cannot be false/undefined/null
* @param {Boolean} forceQueuing Optional (defaults to false) force executor to queue task even if it is not ready
*/
Executor.prototype.push = function (task, forceQueuing) {

Loading…
Cancel
Save