awaitLeadership

open suspend fun awaitLeadership()

Suspends until this node is observed in the RaftRole.Leader role.

Convenience over polling role.value. Returns immediately if already leader. Honours structured concurrency: if the surrounding scope is cancelled while waiting, this throws kotlinx.coroutines.CancellationException. A RaftRole.Learner never becomes leader, so calling this on a learner node suspends forever (until cancelled).

Example:

node.awaitLeadership()
// this node is now the leader — safe to propose