You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
First of all thanks for your work on this great library !
I am currently using redux-saga in a react-native project in order to handle the background refresh of my app, my issue is that the background refresh is only executed once then it looks like it is stuck on a delay (see explication below).
The workflow uses two principal sagas (main and backgroundRefresh) :
Main Saga
In a while loop, Take the START_BACKGROUND_REFRESH action
Fork the backgroundRefresh task
Start a while loop
Start a Race between the REFRESH_NOW and the STOP_BACKGROUND_REFRESH actions
Depending on the action that won the race:
a. If the action was REFRESH_NOW then cancel the backgroundRefresh task and re-fork it
b. If the action was STOP_BACKGROUND_REFRESH then cancel the backgroundRefresh task and restart at 1
BackgroundRefesh Saga
Put the REFRESH_STARTED action
Call a function (returns a set of credentials)
Call multiple subSagas using yield all() (the sagas are fetching the API and dispatching the corresponding actions)
Put the REFRESH_COMPLETED action
Wait a delay of 30 seconds then if not cancelled restart at 1
The goal is to allow a continuous background refresh once the START_BACKGROUND_REFRESH has been put and as long as the STOP_BACKGROUND_REFRESH has not been put but also to allow an instant refresh with the REFRESH_NOW action.
My issue is with the delay of 30 seconds in the BackgroundRefresh Saga, the saga is just stuck on this delay, it never ends (it ends only when the time is much smaller, like 1 second, in that case it works correctly).
I have tried to run only the BackgroundRefresh saga without the Main one, in that case it works correctly but I need the ability to stop, start and instantly start the refresh process.
Here is a slightly simplified version of the code :
import{take,put,call,fork,cancel,cancelled,all,select,race}from'redux-saga/effects';import{delay}from'redux-saga';import*astypesfrom"../../constants/actionTypes";function*mainSaga(){while(yieldtake(types.START_BACKGROUND_REFRESH)){letbgSyncTask=yieldfork(backgroundRefresh);while(true){const{refreshNow, stopNow}=yieldrace({refreshNow: take(types.REFRESH_NOW),stopNow: take(types.STOP_BACKGROUND_REFRESH)});yieldcancel(bgSyncTask);if(refreshNow){bgSyncTask=yieldfork(backgroundRefresh);}elseif(stopNow){break;}}}}function*backgroundRefresh(){try{while(true){yieldput({type: types.REFRESH_STARTED});letcredentials=yieldcall(getCredentials);yieldall([call(updateData,credentials)//Other similar calls]);yieldput({type: types.REFRESH_COMPLETED});yieldcall(delay,30000);}}finally{if(yieldcancelled()){console.log("CANCELED BY SAGA");}else{console.error("CANCELED UNEXPECTEDLY");}}}asyncfunctiongetCredentials(){returnawaitsecureStore.getCredentials();}function*updateData(credentials){letdata=yieldcall(fetchData,credentials);if(data.response&&!data.error){yieldput({type: types.UPDATE_BALANCE,balance: data.response});}}asyncfunctionfetchData(credentials){try{letresponse=awaitapiClient.getData(credentials);return{response};}catch(error){return{error};}}exportdefaultfunction*appSagas(){yieldall([mainSaga()]);}
Do you have any idea of what could cause such an issue ?
I am new to redux-saga so I guess I made a mistake somewhere in the workflow or overcomplicated the problem.
Thanks !
The text was updated successfully, but these errors were encountered:
Im thinking it might be some react-native issue, are there any known timer bugs? I think Ive heard about some, but aint sure as im not into react native programming atm.
In general delay is just promisifying setTimeout, its a really thin wrapper - so it doesnt matter if u use 10 or 1000000 as its argument. Its just a setTimeout under the hood.
Could you maybe try to plug in with sagaMonitor to ur middleware and log ur effects? It would help diagnosing the problem. I would only ask you to comment out unrelated sagas to keep the log clean.
You are right, the issue is related to facebook/react-native#9436. I just tried without the remote debugger and the saga works perfectly. Sorry for the unrelated issue.
I have also tried to plug in sagaMonitor, unfortunately my attempt was unsuccessful, I encountered the issue mentioned here redux-saga/redux-saga-devtools#13 and another one due to the use of the race effect, I will open another issue on the corresponding repository with more details.
Hello,
First of all thanks for your work on this great library !
I am currently using redux-saga in a react-native project in order to handle the background refresh of my app, my issue is that the background refresh is only executed once then it looks like it is stuck on a delay (see explication below).
The workflow uses two principal sagas (main and backgroundRefresh) :
Main Saga
a. If the action was REFRESH_NOW then cancel the backgroundRefresh task and re-fork it
b. If the action was STOP_BACKGROUND_REFRESH then cancel the backgroundRefresh task and restart at 1
BackgroundRefesh Saga
The goal is to allow a continuous background refresh once the START_BACKGROUND_REFRESH has been put and as long as the STOP_BACKGROUND_REFRESH has not been put but also to allow an instant refresh with the REFRESH_NOW action.
My issue is with the delay of 30 seconds in the BackgroundRefresh Saga, the saga is just stuck on this delay, it never ends (it ends only when the time is much smaller, like 1 second, in that case it works correctly).
I have tried to run only the BackgroundRefresh saga without the Main one, in that case it works correctly but I need the ability to stop, start and instantly start the refresh process.
Here is a slightly simplified version of the code :
Do you have any idea of what could cause such an issue ?
I am new to redux-saga so I guess I made a mistake somewhere in the workflow or overcomplicated the problem.
Thanks !
The text was updated successfully, but these errors were encountered: