redux-saga: tracking multiple async tasks

592 views Asked by At

I am using sagas to track multiple async tasks, but there is one problem I haven't been able to completely solve:

function* performTask1() {
    // Some logic here to takeLatest for the relevant component

    // check if component id matches?

    // Only perform API call with the latest
    const { result } = yield takeLatest('doAsync2')
}

function* performTask2() {
    const { result } = yield call(api, args)
    // do something with results (not relevant)
}

function* watchAsyncTasks() {
    yield takeEvery('doAsync2', performTask2)
    yield takeEvery('doAsync1', performTask1)
}
  1. componentA dispatches doAsync1
  2. componentB dispatches doAsync1

  3. component C dispatches doAsync2 (for good measure)

  4. componentA dispatches doAsync1

  5. componentB dispatches doAsync1

How can I use sagas to ensure that only sagas 3, 4, and 5 complete their API call?

1

There are 1 answers

2
Marty On BEST ANSWER

function* generator(){
    yield call(api,params);
    yield call(api2, params2);
}

const gen = generator;

gen.next() // done: false/true
gen.next() // done: false/true