Anton Lakotka [JB]
04/26/2019, 7:30 PMval 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.Pavlo Liapota
04/26/2019, 8:37 PM