1 /* eslint-disable curly, @typescript-eslint/no-throw-literal */
2 import type { Action } from 'redux';
3 import type { Task } from 'redux-saga';
4 import { all, cancel, fork, take } from 'redux-saga/effects';
6 import { api } from '@proton/pass/lib/api/api';
7 import { startEventPolling, stopEventPolling } from '@proton/pass/store/actions';
8 import type { RootSagaOptions } from '@proton/pass/store/types';
9 import { logger } from '@proton/pass/utils/logger';
11 import { invitesChannel } from './channel.invites';
12 import { shareChannels } from './channel.share';
13 import { sharesChannel } from './channel.shares';
14 import { userChannel } from './channel.user';
16 function* eventsWorker(options: RootSagaOptions): Generator {
17 yield all([userChannel, shareChannels, sharesChannel, invitesChannel].map((effect) => fork(effect, api, options)));
20 export default function* watcher(options: RootSagaOptions): Generator {
21 while (yield take(startEventPolling.match)) {
22 logger.info(`[ServerEvents] start polling all event channels`);
23 const events = (yield fork(eventsWorker, options)) as Task;
24 const action = (yield take(stopEventPolling.match)) as Action;
25 logger.info(`[ServerEvents] cancelling all event channels [${action.type}]`);