Mutable

class Mutable(locked: Boolean = false) : SmartMutex(source)

Mutable variant of SmartMutex. With that variant you may lock and unlock. Besides, you may create Immutable variant of this instance with immutable factory

Parameters

locked

Preset state of isLocked and its internal _lockStateFlow

Constructors

Link copied to clipboard
constructor(locked: Boolean = false)

Properties

Link copied to clipboard
open val isLocked: Boolean
Link copied to clipboard
open override val lockStateFlow: StateFlow<Boolean>

Functions

Link copied to clipboard
Link copied to clipboard
suspend fun lock()
Link copied to clipboard
suspend fun tryLock(): Boolean
Link copied to clipboard
suspend fun unlock(): Boolean
Link copied to clipboard

Will wait until the SmartMutex.lockStateFlow of this instance will be false.

Link copied to clipboard
inline suspend fun <T> SmartMutex.Mutable.withLock(action: () -> T): T

Will call SmartMutex.Mutable.lock, then execute action and return the result after SmartMutex.Mutable.unlock