async.each callback could be called more than once when array is modified
See original GitHub issuevar async = require('async')
inputs = [1,2]
async.each(inputs,
function (item, callback) {
setTimeout(function(){callback()}, 1000)
},
function(err){
console.log("async.each done")
})
inputs.splice(1,1)
/* output is:
async.each done
async.each done
*/
the problem is async use completed >= arr.length to check if call callback. however arr.length is less than async.each was called.
Issue Analytics
- State:
- Created 9 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
async.each final callback is being called before the iterators ...
Your problem is that printvals does call the cb before it actually has finished logging the value. async.each can only wait for the...
Read more >async.mjs
If the function passed to `asyncify` returns a Promise, that promises's * resolved/rejected state will be used to call the callback, rather than...
Read more >Array.prototype.forEach() - JavaScript - MDN Web Docs
The forEach() method executes a provided function once for each array ... while using promises (or async functions) as forEach callbacks.
Read more >async - Documentation - GitHub Pages
A callback which is called as soon as any iteratee returns true , or after all the iteratee functions have finished. Result will...
Read more >async
The iterator is passed a callback(err) which must be called once it has completed. ... The same as each only no more than...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Modifying the array causes undefined behavior. If you need to modify the array, use
async.queue
.ok cool thanks