0

What's the difference between join and all in Redux Saga?

function* fetchUserData(userId) {
  const postsTask = yield fork(fetchAlbums, userId)
  const albumsTask = yield fork(fetchPosts, userId)
  
  yield join([postsTask, albumsTask])
}
function* fetchUserData(userId) {
  const postsTask = yield fork(fetchAlbums, userId)
  const albumsTask = yield fork(fetchPosts, userId)
  
  yield all([postsTask, albumsTask])
}

Seems that both of them just syncing several tasks.

vadimkorr
  • 116
  • 6

1 Answers1

0

in short, one is "synchronous"/join and the other "asynchronous"/all,

looking at the documentation:

join([...tasks]) = It wraps the array of tasks in join effects, roughly becoming the equivalent of yield tasks.map(t => join(t)) - https://redux-saga.js.org/docs/api/#jointask

join will resolve to the same outcome of the joined task (success or error). If the joined task is cancelled, the cancellation will also propagate to the Saga executing the join effect. Similarly, any potential callers of those joiners will be cancelled as well.

and:

all([...effects]) - parallel effects = Creates an Effect description that instructs the middleware to run multiple Effects in parallel and wait for all of them to complete. It's quite the corresponding API to standard Promise#all - https://redux-saga.js.org/docs/api/#alleffects---parallel-effects

oieduardorabelo
  • 2,687
  • 18
  • 21