Skip to content

async loop solution does not pass #63

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

Closed
connor11528 opened this issue Aug 2, 2014 · 7 comments
Closed

async loop solution does not pass #63

connor11528 opened this issue Aug 2, 2014 · 7 comments

Comments

@connor11528
Copy link

I use your solution code for async-loops but still does not pass. The exercise (run or verify) haaaangs.

code:

function loadUsers(userIds, load, done) {
  var completed = 0
  var users = []
  userIds.forEach(function(id, index) {
    load(id, function(user) {
      console.log(user) // logs out one or two user objects
      users[index] = user
      if (++completed === userIds.length) return done(users)
    })
  })
}

module.exports = loadUsers

not passing for me

@timoxley
Copy link
Owner

timoxley commented Aug 2, 2014

my apologies, I'll look into it asap.

@timoxley
Copy link
Owner

timoxley commented Aug 2, 2014

whoa yeah something is weird with this

@timoxley
Copy link
Owner

timoxley commented Aug 2, 2014

actually, your problem is the console.log in there. Remove it and you should be fine.

@cottyard
Copy link

I get the same hanging problem with the solution code(no console.log used). It prints the correct output once in a while and hangs most of the times. My nodejs version is v0.10.30.

@timoxley
Copy link
Owner

really weird, hm.

@timoxley
Copy link
Owner

@jasonshark @cottyard nodeschool/discussions#486 (comment)

Fixed in 0.0.27.

@igorbelykh86
Copy link

Hello,
I've solved this problem by following way:

function loadUsers(userIds, load, done) {
    var users = {length: 0};
    userIds.forEach(function(val, index) {
        load(val, function(data) {
            users[index] = data;
            if(++users.length == userIds.length) done(Array.prototype.slice.call(users, 0));
        });
    });
}

Why this solution is worse?

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

No branches or pull requests

4 participants