How to use the broadcast-channel/leader-election.create function in broadcast-channel

To help you get started, we’ve selected a few broadcast-channel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github avkonst / hookstate / examples / src / examples / plugin-persistence2.tsx View on Github external
function subscribeBroadcastChannel(
    topic: string,
    onMessage: (m: T) => void,
    onLeader: () => void): BroadcastChannelHandle {
    const channel = new BroadcastChannel(topic);
    channel.onmessage = (m) => onMessage(m);
    const elector = LeaderElection.create(channel);
    elector.awaitLeadership().then(() => onLeader())
    return {
        topic,
        channel,
        elector,
        onMessage,
        onLeader
    }
}
function unsubscribeBroadcastChannel(handle: BroadcastChannelHandle) {
github pubkey / rxdb / dist / es / plugins / leader-election.js View on Github external
function LeaderElector(database) {
    this.destroyed = false;
    this.isLeader = false;
    this.isDead = false;
    this.database = database;
    this.elector = createLeaderElection(database.broadcastChannel);
  }
github pubkey / rxdb / src / plugins / leader-election.js View on Github external
constructor(database) {
        this.destroyed = false;
        this.database = database;
        this.isLeader = false;
        this.isDead = false;
        this.elector = LeaderElection.create(database.broadcastChannel);
    }

broadcast-channel

A BroadcastChannel that works in New Browsers, Old Browsers, WebWorkers, NodeJs, Deno and iframes

MIT
Latest version published 1 year ago

Package Health Score

78 / 100
Full package analysis