Skip to content

Instantly share code, notes, and snippets.

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 bingex/e45cd56bcb1c1eaeee3176c85976ac96 to your computer and use it in GitHub Desktop.
Save bingex/e45cd56bcb1c1eaeee3176c85976ac96 to your computer and use it in GitHub Desktop.
import {put, call, cancelled} from 'redux-saga/effects';
function* uploadMediaWorker(action) {
const abortController = new AbortController();
try {
yield put(actions.uploadMediaStart());
const response = yield call(uploadService.uploadMedia, {
signal: abortController.signal,
file: action.payload
});
yield put(actions.uploadMediaSuccess());
} catch (error) {
yield put(actions.uploadMediaFail());
} finally {
if (yield cancelled()) {
abortController.abort();
yield put(actions.uploadMediaFail());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment