ReadonlynameStatic ReadonlyprefixPrefix used in the namespace for election-based operations.
Puts the value as eligible for election. Multiple sessions can participate in the election, but only one can be the leader at a time.
A common pattern in cluster-based applications is to campaign the hostname or IP of the current server, and allow the leader server to be elected among them.
You should listen to the error and elected events on the returned
object to know when the instance becomes the leader, and when its campaign
fails. Once you're finished, you can use Campaign.resign to
forfeit its bid at leadership.
Once acquired, instance will not lose its leadership unless resign()
is called, or error is emitted.
Returns the currently-elected leader value (passed to campaign() or
proclaim()), or undefined if there's no elected leader.
Optionalencoding: BufferEncodingReturns the currently-elected leader value (passed to campaign() or
proclaim()), or undefined if there's no elected leader.
Creates an observer for the election, which emits events when results
change. The observer must be closed using observer.cancel() when
you're finished with it.
Implementation of elections, as seen in etcd's Go client. Elections are most commonly used if you need a single server in charge of a certain task; you run an election on every server where your program is running, and among them they will choose one "leader".
There are two main entrypoints: campaigning via Election.campaign, and observing the leader via Election.observe.
See
https://github.com/etcd-io/etcd/blob/master/client/v3/concurrency/election.go
Example