|
|
@ -11,12 +11,7 @@ executor = async.queue(function (task, cb) { |
|
|
|
, lastArg = task.arguments[task.arguments.length - 1] |
|
|
|
, lastArg = task.arguments[task.arguments.length - 1] |
|
|
|
; |
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
//console.log("==================");
|
|
|
|
// Always tell the queue task is complete. Execute callback if any was given.
|
|
|
|
//console.log(task);
|
|
|
|
|
|
|
|
//console.log('---');
|
|
|
|
|
|
|
|
//console.log(lastArg);
|
|
|
|
|
|
|
|
//console.log("==================");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof lastArg === 'function') { |
|
|
|
if (typeof lastArg === 'function') { |
|
|
|
callback = function () { |
|
|
|
callback = function () { |
|
|
|
lastArg(arguments); |
|
|
|
lastArg(arguments); |
|
|
@ -33,7 +28,7 @@ executor = async.queue(function (task, cb) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
task.fn.apply(task.this, task.arguments); |
|
|
|
task.fn.apply(task.this, task.arguments); |
|
|
|
}, 2); |
|
|
|
}, 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function test1 (msg, cb) { |
|
|
|
function test1 (msg, cb) { |
|
|
@ -61,7 +56,7 @@ function test2 (msg, cb) { |
|
|
|
|
|
|
|
|
|
|
|
function bloup () { console.log("FINISHED"); } |
|
|
|
function bloup () { console.log("FINISHED"); } |
|
|
|
|
|
|
|
|
|
|
|
executor.push({ this: null, fn: test1, arguments: [ 'world', bloup ] }); |
|
|
|
executor.push({ this: null, fn: test1, arguments: [ 'world' ] }); |
|
|
|
executor.push({ this: null, fn: test2, arguments: [ 'world', bloup ] }); |
|
|
|
executor.push({ this: null, fn: test2, arguments: [ 'world', bloup ] }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -123,42 +118,7 @@ q.unshift({name: 'bar'}, function (err) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
function Executor () { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Executor.prototype.enqueueAction = function (fn, thisArg) { |
|
|
|
|
|
|
|
var callback |
|
|
|
|
|
|
|
, self = this |
|
|
|
|
|
|
|
, lastArg = arguments[arguments.length - 1]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(arguments); |
|
|
|
|
|
|
|
console.log(arguments.length); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// When finishing action, we need to launch the next one. We may also need to execute the callback for that action
|
|
|
|
|
|
|
|
if (lastArg === 'function') { |
|
|
|
|
|
|
|
callback = function () { |
|
|
|
|
|
|
|
lastArg(arguments); |
|
|
|
|
|
|
|
self.launchNextAction(); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
callback = function () { |
|
|
|
|
|
|
|
self.launchNextAction(); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Executor.prototype.launchNextAction = function () { |
|
|
|
|
|
|
|
console.log("LAUNCHED NEXT ACTION"); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var e = new Executor(); |
|
|
|
|
|
|
|
e.enqueueAction(console.log, null, "a", 42); |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Interface
|
|
|
|
// Interface
|
|
|
|
//module.exports = Executor;
|
|
|
|
module.exports = executor; |
|
|
|