在 redux saga 中产生所有(并行请求)到队列中? [英] yield all (parallel requests) into queue in redux saga?

查看:46
本文介绍了在 redux saga 中产生所有(并行请求)到队列中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有传奇:

function* sagaA() {         // accumulates all user requests
   // do stuff
   yield all(users.map((user) => call(sagaB, user));
   yield put(SUCCESS ACTION);
}

function* sagaB(user) {     // is responsible for single request
   yield call(api, user);
   // do stuff
}

function* watch() {       // watches for the action
   yield take('REQUEST', sagaA);
}

然而,在这种情况下,请求是并行的,它们没有排队.

However, in this case the requests are parallel, they are not queued.

问题:如何修改这个传奇,让它们被一个一个地调用?

Question: how to modify this sagas so they are being called one by one?

推荐答案

您可以使用常规的 for 循环:

You can use regular for loop:

function* sagaA() {
  for(const user of users) {
    yield call(sagaB, user);
  }
  yield put(SUCCESS_ACTION);
}

这篇关于在 redux saga 中产生所有(并行请求)到队列中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆