redux-saga: put.resolve isn't blocking when invoked via an action
I have a saga that has 3 put.resolve(), but it seems put.resolve does not block for my intended use case.
// inits different part of the state tree with some initial data
export function* initSaga (action) {
yield put.resolve(INIT1, 1));
yield put.resolve(INIT2, 2));
yield put.resolve(INIT3, 3));
}
if i invoke this initSaga with a call(), then each put.resolve seems to block. However, if I try to invoke initSaga via an action that was dispatched, then the put.resolves don’t seem to block.
yield call(initSaga) // is blocking yield takeEvery(INIT, initSaga) // is not blocking yield takeEverySync(INIT, initSaga) // is not blocking
I sort of understand why takeEvery wouldn’t block since it uses fork internally, but I dont’ understand why my implementation of takeEverySync does not block.
function* takeEverySync(pattern, saga, ...args) {
const requestChan = yield actionChannel(pattern);
while (true) {
const action = yield take(requestChan);
yield call(saga, ...args.concat(action));
}
}
Is there a way to write takeEvery in a synchronous fashion to make the put.resolve()'s synchronous?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 27 (13 by maintainers)
@granmoe thanks for the boilerplate.
@Andarist http://www.webpackbin.com/Eyni351Dz refer to the saga.js comments I put in to test the two use cases.
My example dispatches the URL_CHANGE action twice to verify that there is a race condition and that put.resolve does not work as I thought it should.
Thanks for all your help guys.