123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- var async = require('../lib/vasync');
- exports['waterfall'] = function(test){
- test.expect(6);
- var call_order = [];
- async.waterfall([
- function(callback){
- call_order.push('fn1');
- setTimeout(function(){callback(null, 'one', 'two');}, 0);
- },
- function(arg1, arg2, callback){
- call_order.push('fn2');
- test.equals(arg1, 'one');
- test.equals(arg2, 'two');
- setTimeout(function(){callback(null, arg1, arg2, 'three');}, 25);
- },
- function(arg1, arg2, arg3, callback){
- call_order.push('fn3');
- test.equals(arg1, 'one');
- test.equals(arg2, 'two');
- test.equals(arg3, 'three');
- callback(null, 'four');
- },
- function(arg4, callback){
- call_order.push('fn4');
- test.same(call_order, ['fn1','fn2','fn3','fn4']);
- callback(null, 'test');
- }
- ], function(err){
- test.done();
- });
- };
- exports['waterfall empty array'] = function(test){
- async.waterfall([], function(err){
- test.done();
- });
- };
- exports['waterfall no callback'] = function(test){
- async.waterfall([
- function(callback){callback();},
- function(callback){callback(); test.done();}
- ]);
- };
- exports['waterfall async'] = function(test){
- var call_order = [];
- async.waterfall([
- function(callback){
- call_order.push(1);
- callback();
- call_order.push(2);
- },
- function(callback){
- call_order.push(3);
- callback();
- },
- function(){
- test.same(call_order, [1,2,3]);
- test.done();
- }
- ]);
- };
- exports['waterfall error'] = function(test){
- test.expect(1);
- async.waterfall([
- function(callback){
- callback('error');
- },
- function(callback){
- test.ok(false, 'next function should not be called');
- callback();
- }
- ], function(err){
- test.equals(err, 'error');
- });
- setTimeout(test.done, 50);
- };
|