Skip to content

Instantly share code, notes, and snippets.

@thisisjofrank
Created April 22, 2022 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thisisjofrank/34238358742b97c867844a72bcb26ec7 to your computer and use it in GitHub Desktop.
Save thisisjofrank/34238358742b97c867844a72bcb26ec7 to your computer and use it in GitHub Desktop.
The election logic is implemented in ensureLeaderElected. We use the members array to determine if a client is the leader. First, it checks the members array passed to the function, and if there is already a leader (someone with the presence data of "leader"), it will stop and return early. There's already a leader, so nothing further needs to b…
private async ensureLeaderElected(members: Types.PresenceMessage[]) {
const leader = members.find(s => s.data === "leader");
if (leader) {
return;
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment