Skip to content

Instantly share code, notes, and snippets.

@nacmartin
Created September 20, 2019 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nacmartin/b9853745f463b53cfd31126ed380cd61 to your computer and use it in GitHub Desktop.
Save nacmartin/b9853745f463b53cfd31126ed380cd61 to your computer and use it in GitHub Desktop.
Infinite call
import * as effects from "redux-saga/effects";
import * as constants from "../actions/constants";
function* processTaskTimeConsuming() {
yield effects.delay(1000 + 1000 * Math.random());
if (Math.random() > 0.5) {
return true;
} else {
throw new Error("Something is not right!");
}
}
export function* doProcessTask(name) {
yield effects.put({ type: constants.TASK_PROCESS_START, name });
try {
yield effects.call(processTaskTimeConsuming);
yield effects.put({ type: constants.TASK_PROCESS_DONE, name });
} catch (error) {
yield effects.put({ type: constants.TASK_PROCESS_ERROR, name });
}
}
export function* rootSaga() {
while (true) {
const action = yield effects.take(constants.TASK_PROCESS);
yield effects.call(doProcessTask, action.name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment