Skip to content

Series is executing in parallel #3

@TuckerWhitehouse

Description

@TuckerWhitehouse

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions