[Pkg-javascript-commits] [node-async] 11/480: updated auto api, removed requires function
Jonas Smedegaard
js at moszumanska.debian.org
Fri May 2 08:58:07 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository node-async.
commit 75d506c34eabf314f34fac8e59ffa991f0fc3660
Author: Caolan McMahon <caolan at caolanmcmahon.com>
Date: Wed May 19 20:20:57 2010 +0100
updated auto api, removed requires function
---
lib/async.js | 25 +++++++------------------
test/test-async.js | 50 ++++++++++++++++----------------------------------
2 files changed, 23 insertions(+), 52 deletions(-)
diff --git a/lib/async.js b/lib/async.js
index 3102bb3..546f00d 100644
--- a/lib/async.js
+++ b/lib/async.js
@@ -1,10 +1,6 @@
var events = require('events');
-exports.requires = function(requirements, fn){
- return {requires: requirements, run: fn};
-};
-
exports.auto = function(tasks, callback){
var keys = Object.keys(tasks);
if(!keys.length) return callback(null);
@@ -18,30 +14,23 @@ exports.auto = function(tasks, callback){
});
keys.forEach(function(k){
- var task = tasks[k];
- if(task instanceof Function){
- task = {run: task};
- }
- var taskEnv = {
- done: function(){
- completed.push(k);
- emitter.emit('taskComplete');
- }
+ var task = (tasks[k] instanceof Function)? [tasks[k]]: tasks[k];
+ var taskCallback = function(){
+ completed.push(k);
+ emitter.emit('taskComplete');
};
- var requires = task.requires || [];
+ var requires = task.slice(0, Math.abs(task.length-1)) || [];
var ready = function(){
return requires.reduce(function(a,x){
return (a && completed.indexOf(x) != -1);
}, true);
};
- if(ready()){
- task.run(taskEnv);
- }
+ if(ready()) task[task.length-1](taskCallback);
else {
var listener = function(){
if(ready()){
emitter.removeListener('taskComplete', listener);
- task.run(taskEnv);
+ task[task.length-1](taskCallback);
}
};
emitter.addListener('taskComplete', listener);
diff --git a/test/test-async.js b/test/test-async.js
index 0f3321a..a724d99 100644
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -1,48 +1,30 @@
var async = require('async');
-exports.testRequires = function(test){
- var fn = function(){return 'test';};
- test.same(
- async.requires(['task1','task2'], fn),
- {requires: ['task1','task2'], run: fn}
- );
- test.done();
-};
-
exports.testAuto = function(test){
var callOrder = [];
var testdata = [{test: 'test'}];
async.auto({
- task1: {
- requires: ['task2'],
- run: function(task){
- setTimeout(function(){
- callOrder.push('task1');
- task.done();
- }, 100);
- }
- },
- task2: function(task){
+ task1: ['task2', function(callback){
+ setTimeout(function(){
+ callOrder.push('task1');
+ callback();
+ }, 100);
+ }],
+ task2: function(callback){
setTimeout(function(){
callOrder.push('task2');
- task.done();
+ callback();
}, 200);
},
- task3: {
- requires: ['task2'],
- run: function(task){
- callOrder.push('task3');
- task.done();
- }
- },
- task4: {
- requires: ['task1', 'task2'],
- run: function(task){
- callOrder.push('task4');
- task.done();
- }
- }
+ task3: ['task2', function(callback){
+ callOrder.push('task3');
+ callback();
+ }],
+ task4: ['task1', 'task2', function(callback){
+ callOrder.push('task4');
+ callback();
+ }]
},
function(err){
test.same(callOrder, ['task2','task3','task1','task4']);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-async.git
More information about the Pkg-javascript-commits
mailing list