美文网首页
saga 阻塞,非阻塞

saga 阻塞,非阻塞

作者: LoserCfang | 来源:发表于2020-04-26 23:23 被阅读0次

    function* saga() {

      yield take(ACTION)              // 阻塞: 将等待 action

      yield call(ApiFn, ...args)      // 阻塞: 将等待 ApiFn (如果 ApiFn 返回一个 Promise 的话)

      yield call(otherSaga, ...args)  // 阻塞: 将等待 otherSaga 结束

      yield put(...)                  // 阻塞: 将同步发起 action (使用 Promise.then)

      const task = yield fork(otherSaga, ...args)  // 非阻塞: 将不会等待 otherSaga

      yield cancel(task)                          // 非阻塞: 将立即恢复执行

      // or

      yield join(task)                            // 阻塞: 将等待 task 结束

    }

    相关文章

      网友评论

          本文标题:saga 阻塞,非阻塞

          本文链接:https://www.haomeiwen.com/subject/agzjwhtx.html