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()

Holds call until this SmartMutex will be re-locked. That means that while isLocked == true, holds will wait for isLocked == false and then try to lock

Link copied to clipboard
suspend fun tryLock(): Boolean

Will try to lock this SmartMutex immediataly

Link copied to clipboard
suspend fun unlock(): Boolean

If isLocked == true - will change it to false and return true. If current call will not unlock this SmartMutex - false

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