我有以下传说:
function* someSaga(action) {
const { currentUser: { accountId } } = action;
const accountBillingPlanEffect = yield call(getAccountBillingPlan, services['account-billing-plans'], accountId);
const accountBillingPlanResponse = yield (accountBillingPlanEffect.payload.promise);
const { stripeSubscriptionId } = accountBillingPlanResponse.data[0];
const stripeSubscriptionEffect = yield call(getStripeSubscription, services['stripe/subscriptions'], stripeSubscriptionId);
const stripeSubscriptionResponse = yield (stripeSubscriptionEffect.payload.promise);
const { customer } = stripeSubscriptionResponse.data[0];
//The important part
const [stripeCustomerTask, stripeInvoicesTask] = yield all([
fork(getStripeCustomer, services['stripe/customers'], customer),
fork(getStripeInvoices, services['stripe/invoices'], customer),
]);
}
我怎么知道 [stripeCustomerTask,stripeInvoicesTask] 完成的时间?
每个操作完成后,我想执行另一个操作。
答案 0 :(得分:1)
由于它位于all([...])
中,并且您可以从中获得收益,因此只需在其后立即放置代码即可。返回这些值之前,它之后的代码将不执行。你很好!只需继续编码即可。
This is one of the best redux-sagas
blogs I have read to date很好地介绍了这一点。这里的关键部分是:
redux-saga提供
all
效果,该效果采用一系列阻塞效果,并等待所有这些效果完成,然后恢复所有结果。
因此,您可以将代码放在all
之后,并期望拥有这些值。
//The important part
const [stripeCustomerTask, stripeInvoicesTask] = yield all([
fork(getStripeCustomer, services['stripe/customers'], customer),
fork(getStripeInvoices, services['stripe/invoices'], customer),
]);
// keep coding
if (stripeCustomerTask) { ... }