redux-saga:跟踪多个异步任务

时间:2016-12-13 02:58:48

标签: redux react-redux redux-saga saga

我正在使用传奇来跟踪多个异步任务,但有一个问题我无法完全解决:

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调度doAsync1
  2. componentB调度doAsync1

  3. 组件C调度doAsync2(为了更好地衡量)

  4. componentA调度doAsync1

  5. componentB调度doAsync1
  6. 我如何使用传奇来确保只有sagas 3,4和5完成他们的API调用?

1 个答案:

答案 0 :(得分:1)

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

const gen = generator;

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