I'm new to coroutines and trying to leverage them to call a time consuming method a couple of times in less time
fun callAPI(idList: Collection<String>): List<String> {
val storedIds = mutableListOf<String>()
runBlocking {
val ids = idList.map { data ->
async {timeConsumingMethod(data)}
}.map { it.await() }
storedIds.addAll(ids)
}
return storedIds
}
I need all the calls to timeConsumingMethod to run in parallel, but i don't want callAPI to return until after all the timeConsumingMethods finish.
Running this i see the timeConsumingMethods are running synchronously
Can anyone give me a hand in understanding what mistake i'm missing?
async(Dispatchers.IO) { ... }- IR42