首页 > 解决方案 > 当 promise 解决时,redux-saga 调用不会产生。这里会发生什么?

问题描述

这是我的代码:

console.log('call will be made');
const { Status, CallbackUrl } = yield call(fetchUrl, getSsoEndpointUrl(), options);
console.log('call has yielded');

function fetchUrl(url: string, options: RequestInit) {
    return fetch(url, options)
        .then((response) => {
            return response.json();
        })
        .then((data: SsoServerReponse) => {
            console.log('promise resolves', data.data);
            return data.data;
        });
}

我得到以下日志输出:

sagas.ts call will be made
sagas.ts promise resolves {Status: 200, CallbackUrl: "..."}

我不明白这里可能出了什么问题。fetchUrl承诺解决。为什么console.log('call has yielded')永远不会发生?

标签: redux-saga

解决方案


问题是我在代码的其他地方有以下几行:

yield take(LOCATION_CHANGE);
yield cancel(ssoSignInWatcher);

换句话说,通过阅读我的问题几乎不可能猜到这个问题。我正在结束这个问题。


推荐阅读