Skip to main content

Function: createLeader()

function createLeader(name, options?): Leader;

Elects exactly one client on the bus to hold a seat: the tab that owns the WebSocket, polls, or refreshes the token, while the others stand by.

Lease and claim, with a sticky incumbent. A leader re-announces every heartbeatMs; followers give up on it after leaseMs of silence and claim the seat with a higher term. Terms are Versions, arbitrated by the same newer() the store uses, so simultaneous claims resolve deterministically instead of flapping.

Leadership is advisory. It is not a distributed lock, and a hidden tab whose timers are throttled can lose a lease it deserved to keep.

Parameters

ParameterType
namestring
optionsLeaderOptions

Returns

Leader