LifeCycle

class LifeCycle<S : Enum<S>>(initial: S)

This class provides simple tracking of the lifecycle of a service-type object. S is an enum enumerating the possible states the service can be in.

Parameters

initial

The initial state.

Constructors

Link copied to clipboard
constructor(initial: S)

Functions

Link copied to clipboard
fun justTransition(to: S)

Transition the state to to without performing a current state check.

Link copied to clipboard
fun requireState(requiredState: S)
fun requireState(errorMessage: (S) -> String = { "Predicate failed on state $it" }, predicate: (S) -> Boolean)
fun <A> requireState(requiredState: S, throwable: Throwable, block: () -> A): A

fun <A> requireState(requiredState: S, block: () -> A): A

Assert that the lifecycle in the requiredState. Optionally runs block, for the duration of which the lifecycle is guaranteed to stay in requiredState.

fun <A> requireState(errorMessage: (S) -> String, predicate: (S) -> Boolean, block: () -> A): A

Assert something about the current state atomically.

Link copied to clipboard
fun transition(from: S, to: S)

Transition the state from from to to.