Comparing version 0.0.1 to 0.0.2
15
index.js
module.exports = function() { | ||
var n = 0, m = 0, _cb, results = []; | ||
var n = 0, m = 0, _cb, results = [], _err; | ||
return function(cb) { | ||
if (cb) { | ||
results.length = m | ||
if(_err) { | ||
var err = _err; _err = null | ||
return cb(err) | ||
} | ||
if(n == m) | ||
return cb(null, results) | ||
_cb = cb | ||
results.length = m | ||
return | ||
@@ -16,2 +24,3 @@ } | ||
if (err) { | ||
_err = err | ||
n = -1 // stop | ||
@@ -27,2 +36,2 @@ if (_cb) _cb(err) | ||
} | ||
} | ||
} |
{ | ||
"name": "multicb", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Simple way to aggregate multiple node-style callbacks", | ||
"dependencies": { | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"deep-equal": "^0.2.1", | ||
"tape": "~2.12.3" | ||
"tape": "~2.12.3", | ||
"interleavings": "~0.3.0" | ||
}, | ||
@@ -11,0 +11,0 @@ "scripts": { |
'use strict' | ||
var tape = require('tape'); | ||
//var tape = require('tape'); | ||
var equal = require('deep-equal'); | ||
var multicb = require('../') | ||
function async(cb, delay, args) { | ||
setTimeout(function() { cb.apply(null, args) }, delay) | ||
} | ||
var t = require('assert') | ||
module.exports = function(opts) { | ||
tape('multiple callbacks', function(t) { | ||
var done = multicb() | ||
async(done(), 5, [null, 1]) | ||
async(done(), 15, [null, 2]) | ||
async(done(), 10, [null, 3]) | ||
done(function(err, results) { | ||
t.equal(err, null) | ||
t.equal(results[0][1], 1) | ||
t.equal(results[1][1], 2) | ||
t.equal(results[2][1], 3) | ||
t.end() | ||
}) | ||
}) | ||
require('interleavings').test(function (isAsync) { | ||
tape('errors', function(t) { | ||
var done = multicb() | ||
async(done(), 5, [null, 1]) | ||
async(done(), 15, [null, 2]) | ||
async(done(), 10, ['fail']) | ||
done(function(err, results) { | ||
t.equal(err, 'fail') | ||
t.equal(results, void 0) | ||
t.end() | ||
}) | ||
function async(cb, delay, args) { | ||
isAsync(function() { cb.apply(null, args) })() | ||
} | ||
var done = multicb() | ||
async(done(), 5, [null, 1]) | ||
async(done(), 15, [null, 2]) | ||
async(done(), 10, [null, 3]) | ||
done(function(err, results) { | ||
console.log('done') | ||
t.equal(err, null) | ||
t.equal(results[0][1], 1) | ||
t.equal(results[1][1], 2) | ||
t.equal(results[2][1], 3) | ||
isAsync.done() | ||
}) | ||
} | ||
if(!module.parent) | ||
module.exports({ }) | ||
}) | ||
//if(!module.parent) | ||
//module.exports({ }) |
2484
5
74
3