Created
April 22, 2022 13:13
-
-
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…
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
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