fastparallel
Advanced tools
Comparing version 2.0.1 to 2.1.0
{ | ||
"name": "fastparallel", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Zero-overhead asynchronous parallel/each/map function call", | ||
@@ -5,0 +5,0 @@ "main": "parallel.js", |
@@ -66,7 +66,8 @@ 'use strict' | ||
function goResultsArray (that, toCall, arg, holder) { | ||
function goResultsArray (that, funcs, arg, holder) { | ||
var singleCaller = null | ||
holder._count = toCall.length | ||
var toCall = nop | ||
holder._count = funcs.length | ||
holder._results = new Array(holder._count) | ||
for (var i = 0; i < toCall.length; i++) { | ||
for (var i = 0; i < funcs.length; i++) { | ||
singleCaller = queueSingleCaller.get() | ||
@@ -76,3 +77,8 @@ singleCaller._release = singleCallerRelease | ||
singleCaller.pos = i | ||
toCall[i].call(that, arg, singleCaller.release) | ||
toCall = funcs[i] | ||
if (toCall.length === 1) { | ||
toCall.call(that, singleCaller.release) | ||
} else { | ||
toCall.call(that, arg, singleCaller.release) | ||
} | ||
} | ||
@@ -88,6 +94,12 @@ } | ||
function goNoResultsArray (that, toCall, arg, holder) { | ||
holder._count = toCall.length | ||
for (var i = 0; i < toCall.length; i++) { | ||
toCall[i].call(that, arg, holder.release) | ||
function goNoResultsArray (that, funcs, arg, holder) { | ||
var toCall = null | ||
holder._count = funcs.length | ||
for (var i = 0; i < funcs.length; i++) { | ||
toCall = funcs[i] | ||
if (toCall.length === 1) { | ||
toCall.call(that, holder.release) | ||
} else { | ||
toCall.call(that, arg, holder.release) | ||
} | ||
} | ||
@@ -94,0 +106,0 @@ } |
42
test.js
@@ -350,1 +350,43 @@ var test = require('tape') | ||
}) | ||
test('call without arg if there is no arg with no results', function (t) { | ||
t.plan(3) | ||
var instance = parallel({ | ||
results: false | ||
}) | ||
var count = 0 | ||
var obj = {} | ||
instance(obj, [something, something], 42, function done () { | ||
t.equal(count, 2, 'all functions must have completed') | ||
}) | ||
function something (cb) { | ||
t.equal(obj, this) | ||
setImmediate(function () { | ||
count++ | ||
cb() | ||
}) | ||
} | ||
}) | ||
test('call without arg if there is no arg with results', function (t) { | ||
t.plan(3) | ||
var instance = parallel() | ||
var count = 0 | ||
var obj = {} | ||
instance(obj, [something, something], 42, function done () { | ||
t.equal(count, 2, 'all functions must have completed') | ||
}) | ||
function something (cb) { | ||
t.equal(obj, this) | ||
setImmediate(function () { | ||
count++ | ||
cb() | ||
}) | ||
} | ||
}) |
20506
584