Since preemptive multitasking is not available in a browser, and JavaScript is inherently single threaded, how does a Redux Middleware like redux-saga handle infinite loops not designed for cooperative multitasking without triggering the long-running script dialog?
function* watchSaga() {
while (true) {
yield take(SOME_REQUEST);
// do something
}
}
Edit
My statement "not designed for cooperative multitasking" was wrong. A generator function's code is executed only until the first yield expression.
yield
is indeed the key, as it yields control, suspending the current generator function and returning a value to it.A simple example: