我正在使用传奇来跟踪多个异步任务,但有一个问题我无法完全解决:
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)
}
componentB调度doAsync1
组件C调度doAsync2(为了更好地衡量)
componentA调度doAsync1
我如何使用传奇来确保只有sagas 3,4和5完成他们的API调用?
答案 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