Skip to content

Preserve order of settleAll results if error occurs #53

@evenfrost

Description

@evenfrost

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(),
  ]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions