Is there Promise.any like thing in redux saga?

Viewed 20

I know about Redux Saga's all([...effects]) effect combinator that is very similar to Promise.all utility, but I've not found something similar to Promise.any behavior that will:

  • run all effects at the same time

  • fail if all effects fail (otherwise succeed)

  • if fail throw AggregateError of all errors

  • if succeed return nothing or first result

e.g.

export function* getHomeDataSaga() {
  yield* any([
    call(getTopUsersSaga, { payload: undefined }),
    call(getFavoritesSaga, { payload: undefined }),
    call(getTrendingTokensSaga, { payload: undefined }),
    call(getTopCollectionsSaga, { payload: { itemsPerPage: 9, page: 1 } }),
  ]);
}

This would be very useful when you want to group multiple (decomposed) sagas in to a single saga, it won't fail-fast but finish all effects.

0 Answers
Related