question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

async.each callback could be called more than once when array is modified

See original GitHub issue
var 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:closed
  • Created 9 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
aearlycommented, Jun 25, 2017

Modifying the array causes undefined behavior. If you need to modify the array, use async.queue.

0reactions
ORESoftwarecommented, Jun 25, 2017

ok cool thanks

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found