-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Sagas running multiple times and socket closing
- Loading branch information
Lucas Leblow
committed
May 6, 2024
1 parent
e81192e
commit 0060adc
Showing
18 changed files
with
298 additions
and
130 deletions.
There are no files selected for viewing
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
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
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
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
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
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
20 changes: 14 additions & 6 deletions
20
packages/mobile/src/store/nativeServices/nativeServices.master.saga.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
import { all, fork, takeEvery } from 'typed-redux-saga' | ||
import { all, fork, takeEvery, cancelled } from 'typed-redux-saga' | ||
import { nativeServicesCallbacksSaga } from './events/nativeServicesCallbacks' | ||
import { leaveCommunitySaga } from './leaveCommunity/leaveCommunity.saga' | ||
import { flushPersistorSaga } from './flushPersistor/flushPersistor.saga' | ||
import { nativeServicesActions } from './nativeServices.slice' | ||
|
||
export function* nativeServicesMasterSaga(): Generator { | ||
yield all([ | ||
fork(nativeServicesCallbacksSaga), | ||
takeEvery(nativeServicesActions.leaveCommunity.type, leaveCommunitySaga), | ||
takeEvery(nativeServicesActions.flushPersistor.type, flushPersistorSaga), | ||
]) | ||
console.log('nativeServicesMasterSaga starting') | ||
try { | ||
yield all([ | ||
fork(nativeServicesCallbacksSaga), | ||
takeEvery(nativeServicesActions.leaveCommunity.type, leaveCommunitySaga), | ||
takeEvery(nativeServicesActions.flushPersistor.type, flushPersistorSaga), | ||
]) | ||
} finally { | ||
console.log('nativeServicesMasterSaga stopping') | ||
if (yield cancelled()) { | ||
console.log('nativeServicesMasterSaga cancelled') | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,29 @@ | ||
import { all, takeEvery } from 'typed-redux-saga' | ||
import { all, takeEvery, takeLeading, fork, cancelled } from 'typed-redux-saga' | ||
import { nativeServicesMasterSaga } from './nativeServices/nativeServices.master.saga' | ||
import { navigationMasterSaga } from './navigation/navigation.master.saga' | ||
import { initMasterSaga } from './init/init.master.saga' | ||
import { initActions } from './init/init.slice' | ||
import { setupCryptoSaga } from './init/setupCrypto/setupCrypto.saga' | ||
import { publicChannels } from '@quiet/state-manager' | ||
import { showNotificationSaga } from './nativeServices/showNotification/showNotification.saga' | ||
import { clearReduxStore } from './nativeServices/leaveCommunity/leaveCommunity.saga' | ||
|
||
export function* rootSaga(): Generator { | ||
yield all([ | ||
takeEvery(initActions.setStoreReady.type, setupCryptoSaga), | ||
takeEvery(initActions.setStoreReady.type, initMasterSaga), | ||
takeEvery(initActions.setStoreReady.type, navigationMasterSaga), | ||
takeEvery(initActions.setStoreReady.type, nativeServicesMasterSaga), | ||
// Below line is reponsible for displaying notifications about messages from channels other than currently viewing one | ||
takeEvery(publicChannels.actions.markUnreadChannel.type, showNotificationSaga), | ||
]) | ||
console.log('rootSaga starting') | ||
try { | ||
yield all([ | ||
fork(setupCryptoSaga), | ||
fork(initMasterSaga), | ||
fork(navigationMasterSaga), | ||
fork(nativeServicesMasterSaga), | ||
// Below line is reponsible for displaying notifications about messages from channels other than currently viewing one | ||
takeEvery(publicChannels.actions.markUnreadChannel.type, showNotificationSaga), | ||
takeLeading(initActions.canceledRootTask.type, clearReduxStore), | ||
]) | ||
} finally { | ||
console.log('rootSaga stopping') | ||
if (yield cancelled()) { | ||
console.log('rootSaga cancelled') | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
import { Socket } from '../../types' | ||
import { all, takeEvery, takeLeading } from 'typed-redux-saga' | ||
import { all, takeEvery, takeLeading, cancelled } from 'typed-redux-saga' | ||
import { appActions } from './app.slice' | ||
import { closeServicesSaga } from './closeServices.saga' | ||
import { stopBackendSaga } from './stopBackend/stopBackend.saga' | ||
import { loadMigrationDataSaga } from './loadMigrationData/loadMigrationData.saga' | ||
|
||
export function* appMasterSaga(socket: Socket): Generator { | ||
yield* all([ | ||
takeLeading(appActions.closeServices.type, closeServicesSaga, socket), | ||
takeEvery(appActions.stopBackend.type, stopBackendSaga, socket), | ||
takeEvery(appActions.loadMigrationData.type, loadMigrationDataSaga, socket), | ||
]) | ||
console.log('appMasterSaga starting') | ||
try { | ||
yield* all([ | ||
takeLeading(appActions.closeServices.type, closeServicesSaga, socket), | ||
takeEvery(appActions.stopBackend.type, stopBackendSaga, socket), | ||
takeEvery(appActions.loadMigrationData.type, loadMigrationDataSaga, socket), | ||
]) | ||
} finally { | ||
console.log('appMasterSaga stopping') | ||
if (yield cancelled()) { | ||
console.log('appMasterSaga cancelled') | ||
} | ||
} | ||
} |
12 changes: 10 additions & 2 deletions
12
packages/state-manager/src/sagas/appConnection/connection.master.saga.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
import { all, fork } from 'typed-redux-saga' | ||
import { all, fork, cancelled } from 'typed-redux-saga' | ||
import { uptimeSaga } from './uptime/uptime.saga' | ||
|
||
export function* connectionMasterSaga(): Generator { | ||
yield all([fork(uptimeSaga)]) | ||
console.log('connectionMasterSaga starting') | ||
try { | ||
yield all([fork(uptimeSaga)]) | ||
} finally { | ||
console.log('connectionMasterSaga stopping') | ||
if (yield cancelled()) { | ||
console.log('connectionMasterSaga cancelled') | ||
} | ||
} | ||
} |
Oops, something went wrong.