arrow-fx-stm / arrow.fx.stm / STM / acquire
open fun
TSemaphore
.acquire():
Unit
Acquire 1 permit from a TSemaphore.
import arrow.fx.stm.TSemaphore
import arrow.fx.stm.atomically
suspend fun main() {
//sampleStart
val tsem = TSemaphore.new(5)
atomically {
tsem.acquire()
}
//sampleEnd
println("Permits remaining ${atomically { tsem.available() }}")
}
This function will retry if there are no permits available.
See Also
open fun
TSemaphore
.acquire(n:
Int
):
Unit
Acquire n permit from a TSemaphore.
import arrow.fx.stm.TSemaphore
import arrow.fx.stm.atomically
suspend fun main() {
//sampleStart
val tsem = TSemaphore.new(5)
atomically {
tsem.acquire(3)
}
//sampleEnd
println("Permits remaining ${atomically { tsem.available() }}")
}
This function will retry if there are less than n permits available.
See Also
Do you like Arrow?
✖