You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is possible a feature request, rather than a bug, but I think async should be more tolerant of passing in empty collections. This allows more easy chaining of async.each() and other calls as part of other frameworks, where those frameworks may pass an undefined array.
Here's a code fragment which demonstrates what I mean:
var async = require('async');
var emptyArray = undefined;
async.each(emptyArray, function(e) { /* do stuff */ }, function() { console.log("All done"); });
This raises the following error:
/Users/roger/tmp/node_modules/async/lib/async.js:120
if (!arr.length) {
^
TypeError: Cannot read property 'length' of undefined
at Object.async.each (/Users/roger/tmp/node_modules/async/lib/async.js:120:17)
at Object. (/Users/roger/tmp/app.js:5:7)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
The code can be improved, thus:
var async = require('async');
var emptyArray = undefined;
if (emptyArray) async.each(emptyArray, function(e) { /* do stuff */ }, function() { console.log("All done"); });
but this feels like unnecessary boiler plating for a check which could easily be incorporated into async.js.
The text was updated successfully, but these errors were encountered:
This is possible a feature request, rather than a bug, but I think async should be more tolerant of passing in empty collections. This allows more easy chaining of async.each() and other calls as part of other frameworks, where those frameworks may pass an undefined array.
Here's a code fragment which demonstrates what I mean:
var async = require('async');
var emptyArray = undefined;
async.each(emptyArray, function(e) { /* do stuff */ }, function() { console.log("All done"); });
This raises the following error:
/Users/roger/tmp/node_modules/async/lib/async.js:120
if (!arr.length) {
^
TypeError: Cannot read property 'length' of undefined
at Object.async.each (/Users/roger/tmp/node_modules/async/lib/async.js:120:17)
at Object. (/Users/roger/tmp/app.js:5:7)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
The code can be improved, thus:
var async = require('async');
var emptyArray = undefined;
if (emptyArray) async.each(emptyArray, function(e) { /* do stuff */ }, function() { console.log("All done"); });
but this feels like unnecessary boiler plating for a check which could easily be incorporated into async.js.
The text was updated successfully, but these errors were encountered: