One possible solution, as you already mentioned, is to use channels
. Here is an example that should work in your case:
import { channel } from 'redux-saga'
import { put, take } from 'redux-saga/effects'
const downloadFileChannel = channel()
export function* loadFile(id) {
...
const download = RNFS.downloadFile({
...
// push `S_PROGRESS` action into channel on each progress event
progress: (progress) => downloadFileChannel.put({
type: ACTIONS.S_PROGRESS,
progress,
}),
})
...
}
export function* watchDownloadFileChannel() {
while (true) {
const action = yield take(downloadFileChannel)
yield put(action)
}
}
The idea here is that we will push a S_PROGRESS
action on the channel for each progress event that is emitted from RNFS.downloadFile
.
We also have to start another saga function that is listening to each pushed action in a while
loop (watchDownloadFileChannel
). Everytime an action has been taken from the channel, we use the normal yield put
to tell redux-saga
that this action should be dispatched.
I hope this answer will help you.