As I know, you can not get the promise by yield a promise in a generator. And the following test proves it is true. The ret is undefined:
function* foo() {
const ret = yield Promise.resolve(50);
console.log(`ret is ${ret}`);
}
const fooGen = foo();
fooGen.next();
fooGen.next()
But I cannot figure out why I can get the resolved promise value in Redux saga. See the following example (jsfiddle: https://jsfiddle.net/vymgr7de/1/)
// Sagas
function* saga() {
yield call(function*() {
const ret = yield Promise.resolve(50);
yield put({type: "*", payload: `ret is ${ret}`});
});
}
// => ret is 50
What trick does Redux saga play?