Skip to content

Commit

Permalink
use internal _isArray function
Browse files Browse the repository at this point in the history
  • Loading branch information
Caolan McMahon committed Mar 28, 2014
1 parent 29f97dd commit 9f57a35
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

//// cross-browser compatiblity functions ////

var _isArray = Array.isArray || function (obj) {
return toString.call(obj) === '[object Array]';
};

var _each = function (arr, iterator) {
if (arr.forEach) {
return arr.forEach(iterator);
Expand Down Expand Up @@ -475,7 +479,7 @@

async.waterfall = function (tasks, callback) {
callback = callback || function () {};
if (tasks.constructor !== Array) {
if (!_isArray(tasks)) {
var err = new Error('First argument to waterfall must be an array of functions');
return callback(err);
}
Expand Down Expand Up @@ -508,7 +512,7 @@

var _parallel = function(eachfn, tasks, callback) {
callback = callback || function () {};
if (tasks.constructor === Array) {
if (_isArray(tasks)) {
eachfn.map(tasks, function (fn, callback) {
if (fn) {
fn(function (err) {
Expand Down Expand Up @@ -548,7 +552,7 @@

async.series = function (tasks, callback) {
callback = callback || function () {};
if (tasks.constructor === Array) {
if (_isArray(tasks)) {
async.mapSeries(tasks, function (fn, callback) {
if (fn) {
fn(function (err) {
Expand Down Expand Up @@ -678,7 +682,7 @@
concurrency = 1;
}
function _insert(q, data, pos, callback) {
if(data.constructor !== Array) {
if (!_isArray(data)) {
data = [data];
}
if(data.length == 0) {
Expand Down Expand Up @@ -764,7 +768,7 @@
drain: null,
drained: true,
push: function (data, callback) {
if(data.constructor !== Array) {
if (!_isArray(data)) {
data = [data];
}
_each(data, function(task) {
Expand Down

0 comments on commit 9f57a35

Please sign in to comment.