Created
February 14, 2022 14:52
-
-
Save tanner-west/b91d320b68108d26f6b368a41b2ed67f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getUsersAsync() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve([{ name: "Bob", age: 24 }, { name: "Alice", age: 50 }]) | |
}, 3000) | |
}) | |
} | |
export function* getUsersSaga() { | |
try { | |
const users = yield call(getUsersAsync); | |
yield put({ type: 'GET_USERS_SUCCEEDED', payload: users }) | |
} catch (e) { | |
yield put({ type: 'GET_USERS_FAILED', payload: e }) | |
} | |
} | |
export default function* rootSaga() { | |
yield all([ | |
yield takeEvery('GET_USERS_REQUESTED', getUsersSaga) | |
]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment