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

Preserve order of settleAll results if error occurs #53

Open
evenfrost opened this issue Aug 7, 2020 · 1 comment
Open

Preserve order of settleAll results if error occurs #53

evenfrost opened this issue Aug 7, 2020 · 1 comment

Comments

@evenfrost
Copy link

Hi,

Current behavior of settleAll function is that if some promise throws an error, it is removed from the results array and added to errors array. This way the order of promises is broken and additionally, it's hard to guess, from which promise the errors comes. E.g.

  /* As an example, secondPromise() throws an error */
  const {
    results: [
      firstPromiseResult,
      secondPromiseResult, // it contains thirdPromiseResult
      thirdPromiseResult, // it is undefined
    ],
    errors, // it contains array of single error of the second promise
  } = await settleAll([
    firstPromise(),
    secondPromise(),
    thirdPromise(),
  ]);

To my mind, it would be much more intuitive if the order of resolved promises and errors preserved:

  /* As an example, secondPromise() throws an error */
  const {
    results: [
      firstPromiseResult,
      secondPromiseResult, // it contains null/undefined
      thirdPromiseResult, // it contains thirdPromiseResult
    ],
    errors, // it contains [null, secondPromiseError, null]
  } = await settleAll([
    firstPromise(),
    secondPromise(),
    thirdPromise(),
  ]);
@evenfrost
Copy link
Author

Actually I've just checked the documentation and it says that the order should be preserved:

For resolved promises, the result array contains the resolved value at the same index as the promise. For rejected promises, the result array contains the return value of errFn at the same index as the promise.

So I assume this is a bug. I'm using v1.27.0.

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

1 participant