'Which dispatcher in Kotlin coroutines should be chosen for multiple parallel requests to MongoDB?
There is a list of parameters each of which is an input for MongoDB query.
Queries might be different, but for simplicity let's keep only one encapsulated in callMongoReactive.
fun callMongoReactive(p: Param): Mono<Result>{
// ...
}
fun queryInParallel(parameters: List<Param>): List<Result> =
parameters
.map { async { mongo.findSomething(it).awaitSingle() } }
.awaitAll()
Suppose parameters list size is not greater than 20.
What is the optimal strategy of coroutine dispatchers usage that makes these async requests run in parallel simultaneously?
Should a custom dispatcher (with a dedicated thread pool) be created or is there a standard approach for such situations?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
