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.every is short-cutting #968

Closed
hotaru355 opened this issue Dec 1, 2015 · 2 comments
Closed

async.every is short-cutting #968

hotaru355 opened this issue Dec 1, 2015 · 2 comments
Labels

Comments

@hotaru355
Copy link
Contributor

From running the below code, it seems that async.every() is short-cutting if a falsy value is returned from an iterator. It would be nice to have this documented, so others don't have to try it out as I did:

async.every([1, 2], function(n, cbEvery) {
  if (n ==1) {
    return setTimeout(function() {
      cbEvery(true)
      console.log('validated')
    }, 1000) 
  } else  {
    cbEvery(false)
  }
}, function(valid) {
  console.log('is valid:', valid)
})

// prints out "is valid: false" BEFORE "validated"

To give this some context: I am running validation on a collection and would like to collect all errors as well as the final isValid boolean. With every() however, I can only get the first failing error and from looking at issue 125 I was under the impression that all iterators would run. Could you please clarify.

@aearly aearly added the docs label Dec 1, 2015
@aearly
Copy link
Collaborator

aearly commented Dec 1, 2015

Yep, that's true -- pretty common behavior for these type of functions in other libraries. I'd be open to a PR for the readme.

@hotaru355
Copy link
Contributor Author

PR: #971

@aearly aearly closed this as completed in 0469948 Dec 2, 2015
aearly added a commit that referenced this issue Dec 2, 2015
Bug fix #968: uddate Readme for `async.every()`
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

2 participants