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

Types

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

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

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

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

Functions

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.