Skip to content
Leader docs0.4

Choose an execution API

Archived Based on Leader release 0.4.0

Keep the elector API aligned with the application’s concurrency model and cancellation rules.

LeaderElector runs a synchronous lambda on the caller path. AsyncLeaderElector accepts a CompletableFuture action and defaults to the virtual-thread executor. Use blocking APIs for bounded imperative jobs; use the async API when the surrounding contract already exposes futures.

VirtualThreadLeaderElector accepts a direct lambda and returns VirtualFuture. It is useful for many blocking election attempts on Java 21+, but it does not turn blocking backend calls into non-blocking I/O. Size backend connections independently.

SuspendLeaderElector is the natural choice in coroutine services. Use native suspend backends such as Exposed R2DBC when end-to-end non-blocking behavior matters. Do not bridge a suspend-only delegate through runBlocking; cancellation must release the scoped lease and propagate.

All models offer explicit result variants. Cancellation is not converted to ActionFailed: blocking and suspend paths rethrow it, while future-based paths complete exceptionally. Test the observation point your caller actually uses, such as await() or join().