# SmartSemaphore

sealed interface SmartSemaphore (source)

It is interface which will work like classic Semaphore, but in difference have permitsStateFlow for listening of the SmartSemaphore 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 permitsStateFlow equal to its Mutable creator

#### Inheritors

Immutable
Mutable

## Types

Immutable
Link copied to clipboard
class Immutable (val permitsStateFlow: StateFlow< Int >, val maxPermits: Int ) : SmartSemaphore

Immutable variant of SmartSemaphore. In fact will depend on the owner of permitsStateFlow

Mutable
Link copied to clipboard
class Mutable (permits: Int , acquiredPermits: Int = 0) : SmartSemaphore

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

## Properties

freePermits
Link copied to clipboard
open val freePermits : Int
maxPermits
Link copied to clipboard
abstract val maxPermits : Int
permitsStateFlow
Link copied to clipboard
abstract val permitsStateFlow : StateFlow< Int >

## Functions

waitRelease
Link copied to clipboard
suspend fun SmartSemaphore . waitRelease (permits: Int = 1): Int

Will wait until the SmartSemaphore.permitsStateFlow of this instance will have permits count free permits.

waitReleaseAll
Link copied to clipboard
suspend fun SmartSemaphore . waitReleaseAll (): Int