christophsturm
11/29/2021, 8:59 AMGerard Klijs
11/29/2021, 9:18 AMchristophsturm
11/29/2021, 9:48 AMGerard Klijs
11/29/2021, 9:55 AMchristophsturm
11/29/2021, 9:57 AMScott Christopher
11/29/2021, 9:58 AMCoroutineDispatcher.limitedParallelism
would be useful. In the interim, I make use of a bounded Channel for a similar use case.christophsturm
11/29/2021, 9:59 AMScott Christopher
11/29/2021, 9:59 AMchristophsturm
11/29/2021, 10:00 AMScott Christopher
11/29/2021, 10:01 AMlimitedParallelism
here: https://github.com/Kotlin/kotlinx.coroutines/issues/2919christophsturm
11/29/2021, 10:03 AMScott Christopher
11/29/2021, 10:03 AMchristophsturm
11/29/2021, 10:05 AMRobert Jaros
11/29/2021, 10:06 AMchristophsturm
11/29/2021, 10:10 AMScott Christopher
11/29/2021, 10:39 AMclass Pool<A> private constructor(private val channel: Channel<A>) {
suspend fun borrow(fn: suspend (A) -> Unit) {
val item = channel.receive()
fn(item)
channel.send(item)
}
companion object {
suspend fun <A> create(size: Int, factory: suspend () -> A): Pool<A> {
val channel = Channel<A>(size)
repeat(size) {
channel.send(factory())
}
return Pool(channel)
}
}
}
Nick Allen
11/29/2021, 8:43 PMwithPermit
extension method.christophsturm
11/30/2021, 7:32 AM