Blog>
Snippets

Parallel Tasks Execution

Show how to execute multiple tasks in parallel using the `all` effect in Redux Saga, ideal for scenarios where multiple data fetching operations need to occur simultaneously.
import { all, call } from 'redux-saga/effects';

function* fetchUsers() {
  // logic to fetch users
}

function* fetchProjects() {
  // logic to fetch projects
}

function* fetchActivities() {
  // logic to fetch activities
}
Three separate saga worker functions for fetching users, projects, and activities, representing the parallel tasks to be executed.
function* rootSaga() {
  yield all([
    call(fetchUsers),
    call(fetchProjects),
    call(fetchActivities)
  ]);
}
Root saga where 'all' effect is used to execute the fetchUsers, fetchProjects, and fetchActivities tasks in parallel. Each saga is initiated with 'call' effect.