Hi, I want to execute N tasks in a pool of K corou...
# announcements
a
Hi, I want to execute N tasks in a pool of K coroutines. How can I do that? I mean:
Copy code
val todos = (0..1000000).map { payload -> someTaskBuilder(payload) }
// On runtime JVM will try to execute as much as it can at the same time.
val results = todos.map { task -> async { task() } }.awaitAll()
// But I want to confine total amount of running coroutines here.
// Something like this:
coroutineScope ( someContextWithCoroutinesLimit ) {
   /* todos execution */
}
Maybe I want something strange. The reason why I want that is an external system which does some work during task execution. And that external system has Connection Limit. I could fix that by using some Pool. But I was wondering is it possible to limit somehow coroutines amount in easy way.
p