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

Series is executing in parallel #3

Closed
TuckerWhitehouse opened this issue Jan 30, 2017 · 1 comment · Fixed by #4
Closed

Series is executing in parallel #3

TuckerWhitehouse opened this issue Jan 30, 2017 · 1 comment · Fixed by #4

Comments

@TuckerWhitehouse
Copy link

From what I can tell, the series method is actually executing all of the methods when it's called, and then waiting for each one to resolve in series before adding it to the array. I think the expected behavior would be that each method is not called until the previous one has resolved.

series([1,2,3,4].map((n) => {
  return async () => new Promise((resolve) => {
    console.log(n)
    setTimeout(() => resolve(n), 1000)
  })
}))

Expected: Each number is logged out 1 second after the previous, total runtime is ~4 seconds
Actual: All numbers are printed immediately, total runtime is ~1 second

I think one way of solving this would be to remove https://github.com/developit/asyncro/blob/master/src/util.js#L6
And change https://github.com/developit/asyncro/blob/master/src/util.js#L6 to be
acc.push(await v());, but I'm not sure if that's the best way.
** This would break the parallel method, so no go there

@developit
Copy link
Owner

Hmm, interesting. Actually that seems to be how series() used to work. I don't recall why it was changed.

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

Successfully merging a pull request may close this issue.

2 participants