# 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

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

## Properties

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

## Functions

immutable
Link copied to clipboard
fun immutable (): SmartMutex.Immutable
lock
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

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

Will try to lock this SmartMutex immediataly

unlock
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

waitUnlock
Link copied to clipboard
suspend fun SmartMutex . waitUnlock (): Boolean

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

withLock
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