Home > front end >  How "call" helper(effect) function in redux-saga return the resolved value instead a promi
How "call" helper(effect) function in redux-saga return the resolved value instead a promi

Time:05-22

I do not understand what the mechanism of the call method is and that it should naturally yield a promise, but instead return the resolved value of that promise.

CodePudding user response:

The source code for the call effect can be found here

The call effect starts by calling whatever you asked it to call, then it checks what was returned. If you return a promise (eg, if you use call with an async function), it waits for that promise to resolve, via a helper function called resolvePromise. resolvePromise basically just calls .then on the promise, and then calls the callback, with the callback being the function that will resume the saga.

If you return an iterator (eg, if you use call with a saga), it hands control over to the proc function, which is the function responsible for running sagas. That code also checks for promises and waits for them to resolve, on this line

  • Related