Title: Theory / Unimportant / CS / Programming / Kotlin / Library / Semaphore
On every note of this deck, unless a note says otherwise:
Page: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/index.html

Typ: Semaphore
Meaning: A counting semaphore for coroutines that logically maintains a number of available permits.
Page: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/index.html
Language: Kotlin

Instruction: semaphore.acquire()
Effect: block until a permit is available, then get a permit
Language: Kotlin
Context: Semaphore
Variables: Semaphore semaphore

Instruction: semaphore.release()
Effect: release a permit
Language: Kotlin
Context: Semaphore
Variables: Semaphore semaphore

Instruction: semaphore.tryAcquire()
Effect: Acquire a permit if one is available, don't block
Language: Kotlin
Context: Semaphore
Returns: Whether a permit was acquired
Variables: Semaphore semaphore

Variable: semaphore.availablePermits
Meaning: The current number of permits available in this semaphore.
Page: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/index.html
Context: Semaphore
Language: Kotlin
Variables: Semaphore semaphore

Instruction: Semaphore(
permits,
aquiredPermits = 0
)
Language: Kotlin
Context: Semaphore
Returns: A new semaphore with permits and aquiredPermits already acquired

Instruction: semaphore.withPermit(action)
Effect: Wait for a permit, request it, execute action and release the permit
Language: Kotlin
Context: Semaphore
Variables: Semaphore semaphore