Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async.each callback called multiple times if result is unshifted #932

Closed
guyellis opened this issue Oct 15, 2015 · 6 comments
Closed

async.each callback called multiple times if result is unshifted #932

guyellis opened this issue Oct 15, 2015 · 6 comments
Labels

Comments

@guyellis
Copy link

I expect this issue is closely related to #557 and #572

var async = require('async');

function func(done) {
  var arr = ['a'];
  async.each(arr, function(item, callback){
    return callback();
  }, function() {
    console.log('done');
    return done(arr);
  });
}

func(function(arr) {
  arr.unshift('a');
  // arr.shift('a') => no problem
});

"done" is printed an infinite number of times.

async version: 0.9.2

node version 0.12.7

@aearly aearly added the bug label Oct 16, 2015
@aearly
Copy link
Collaborator

aearly commented Oct 16, 2015

Thanks for the bug report! 🐛 I think i know what's going on here.

@youqingkui
Copy link

I have not found this to be a bug

@guyellis
Copy link
Author

I should have mentioned that my workaround is to clone arr in func() before calling done(). Not sure if that helps.

@guyellis
Copy link
Author

@youqingkui You ran the snippet I posted and did not see "done" printed an infinite number of times? If so, what versions of node and async are you using?

@youqingkui
Copy link

@guyellis I use node is v4.0.0, async is 1.4.2

var async = require('async');
function func(done) {
  var arr = ['a'];
  async.each(arr, function(item, callback){
    return callback();
  }, function() {
    console.log('done');
    return done(arr);
  });
}

func(function(arr) {
  console.log(arr);
  arr.unshift('a');
  //arr.shift('a');nod
  console.log(arr);
});

// done
// [ 'a' ]
// [ 'a', 'a' ]

@guyellis
Copy link
Author

@youqingkui You're right. The project that I'm working on has a very out-of-date version of async. Looks like it's my problem. Thanks for pointing this out! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants