在`fork`函数上执行`call`会导致return返回挂起?

时间:2018-05-19 06:21:55

标签: redux-saga

我在这样的函数上做call

const didRefresh = yield call(maybeRefresh);
console.log('call - maybeRefresh, didRefresh:', didRefresh); // i expect this to return before the fetch in refreshTask completes

maybeRefresh就是这样:

function* maybeRefresh() {
    const shouldRefresh = true;

    if (shouldRefresh) {
        yield fork(refreshTask);
        console.log('did fork refresh task, should now return while refreshTask happens async');
    }

    const didRefresh = shouldRefresh;
    return didRefresh;
}

function* refreshTask() {
    console.log('will fetch');
    const res = yield call(fetch, 'http://www.blah.com');
    console.log('ok refresh done, status:', res.status); // however its not return until here
}

当我分叉refreshTask时,我希望顶部的yield call在获取之前返回一个值。然而即使"做叉子"得到记录,它似乎挂起,即使它准备返回。它会在返回时挂起,直到分叉任务refreshTask完成,然后返回。这是yield call的工作原理吗?它适用于孩子开始完成的任何异步内容吗?

0 个答案:

没有答案