I'm working on a project that involves computationally intensive tasks that I want to run in parallel. To do so, I'm using multiple async statements to run the tasks and awaitAll to wait until all threads completed computation.
suspend fun tasks() {
coroutineScope {
val result = List (10) {
async {
// do stuff
}
}.awaitAll()
}
}
My question is how to bridge between this code that is run in parallel and regular synchronous code.
I tried to use runBlocking but that seems to run all the async tasks after one another, therefore defeating the whole purpose of using coroutines. The only way I got it to work was to use suspend functions all the way up to the main function, however that is not suitable in my case, as I rely on third-party libraries to call my code from regular functions.
Is there a way to call suspend functions from regular functions while still maintaining their ability to run in parallel?