arrow-fx / arrow.fx / Semaphore / acquireN
abstract fun acquireN(n:
Long
): Kind<F,
Unit
>
Acquires n resources Suspending the Fiber running the action until the resources are available.
import arrow.fx.*
import arrow.fx.extensions.io.async.async
import arrow.fx.extensions.io.monad.flatMap
fun main(args: Array<String>) {
//sampleStart
val semaphore = Semaphore.uncancellable<ForIO>(5, IO.async())
semaphore.flatMap { s ->
s.acquireN(6)
} //Never ends since is uncancellable
semaphore.flatMap { s ->
s.acquireN(5).flatMap {
s.available()
}
}.unsafeRunSync() == 0L
//sampleEnd
}
Do you like Arrow?
✖