Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sagas supervisor #504

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions src/sagas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import { all, fork } from 'redux-saga/effects';
import { all, call, put, spawn } from 'redux-saga/effects';
import { saga as walletSagas } from './wallet';
import { saga as tokensSagas } from './tokens';
import { saga as pushNotificationSaga } from './pushNotification';
Expand All @@ -15,23 +15,35 @@ import { saga as permissionsSagas } from './permissions';
import { saga as walletConnectSagas } from './walletConnect';
import { saga as networkSettingsSagas } from './networkSettings';
import { saga as nanoContractSagas } from './nanoContract';
import { logger } from '../logger';
import { onExceptionCaptured } from '../actions';

const sagas = [
walletSagas,
tokensSagas,
pushNotificationSaga,
networkSettingsSagas,
errorHandlerSagas,
featureToggleSagas,
permissionsSagas,
walletConnectSagas,
nanoContractSagas,
];
function* rootSaga() {
const sagas = [
['walletSagas', walletSagas],
['tokensSagas', tokensSagas],
['pushNotificationSaga', pushNotificationSaga],
['networkSettingsSagas', networkSettingsSagas],
['errorHandlerSagas', errorHandlerSagas],
['featureToggleSagas', featureToggleSagas],
['permissionsSagas', permissionsSagas],
['walletConnectSagas', walletConnectSagas],
['nanoContractSagas', nanoContractSagas],
];

function* defaultSaga() {
yield all(
sagas.map((saga) => fork(saga))
);
yield all(sagas.map(([name, saga]) => spawn(function* supervisor() {
while (true) {
try {
logger('rootSaga').debug(`Starting saga: ${name}`);
yield call(saga)
break
} catch (e) {
// TODO: We should have a retry strategy, e.g. if the wallet saga restarts
// more than 3 times, we should restart the app and yield a fatal exception
yield put(onExceptionCaptured(e, false));
}
}
})));
}

export default defaultSaga;
export default rootSaga;
Loading