Eric Burel
Eric Burel

Reputation: 4924

Run an array of sagas effect sequentially

I am trying to yield an array of saga effects sequentially. The idea is that yield all([call(foo), call(bar]) will run call(foo) and call(bar) in parallel (or at least in a pseudo-parallel fashion).

However, I want my sagas to run sequentially, meaning that I want to wait for foo to end before lauching bar (this way I can cancel the process).

This array of call is generated dynamically, so I can hard write a series of yield. What is the correct syntax in this case ?

Upvotes: 1

Views: 4399

Answers (1)

Martin Campbell
Martin Campbell

Reputation: 1798

The redux-saga documentation has an example of sequencing sagas.

If you have an array of calls, simply yield these in your saga. For example:

// Some array containing call objects
let calls = [...];

// Call each in order they are present in the array
for (let c of calls) {
  yield c
}

Upvotes: 6

Related Questions