# SmartMutex

sealed interface SmartMutex (source)

It is interface which will work like classic Mutex, but in difference have lockStateFlow for listening of the SmartMutex state.

There is Mutable and Immutable realizations. In case you are owner and manager current state of lock, you need Mutable. Otherwise, Immutable.

Any Mutable may produce its Immutable variant which will contains lockStateFlow equal to its Mutable creator

#### Inheritors

Immutable
Mutable

## Types

Immutable
Link copied to clipboard
class Immutable (val lockStateFlow: StateFlow< Boolean >) : SmartMutex

Immutable variant of SmartMutex. In fact will depend on the owner of lockStateFlow

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

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

## Properties

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

## Functions

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

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