Skip to content

Commit

Permalink
use emitter approach
Browse files Browse the repository at this point in the history
  • Loading branch information
denysoblohin-okta committed Dec 1, 2022
1 parent 9ab4055 commit 9fa72ee
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/core/ServiceManager/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { removeNils } from '../../util';
const AUTO_RENEW = 'autoRenew';
const SYNC_STORAGE = 'syncStorage';
const LEADER_ELECTION = 'leaderElection';
const EVENT_ON_LEADER = 'onLeader';

export class ServiceManager
<
Expand Down Expand Up @@ -83,15 +84,13 @@ implements ServiceManagerInterface
if (this.started) {
// Start services that requires leadership
await this.startServices();
await this.options['onLeaderCallback']?.();
this.sdk.emitter.emit(EVENT_ON_LEADER);
}
}

private async waitForLeader() {
return new Promise((resolve) => {
this.options['onLeaderCallback'] = () => {
resolve(null);
};
this.sdk.emitter.once(EVENT_ON_LEADER, resolve);
});
}

Expand Down

0 comments on commit 9fa72ee

Please sign in to comment.