Created
April 5, 2021 20:55
-
-
Save bingex/e45cd56bcb1c1eaeee3176c85976ac96 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
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