acquire
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() }}")
}
Content copied to clipboard
This function will retry if there are no permits available.
See also
for a version that does not retry.
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() }}")
}
Content copied to clipboard
This function will retry if there are less than n permits available.
See also
for a version that does not retry.