Hexa
05/09/2019, 9:43 PMrunBlocking {
coroutineScope {
withTimeoutOrNull(10000L){ // wait time mili seconds
val a: Deferred<Unit> = async { s.deleteItem(xyz) }
val b: Deferred<Unit> = async { s.deleteItem(abc) }
launch {
a.await()
b.await()
}
}
}
}
My async calls returns Deferred<Unit> but I thought it might be better to explicitly call await() on each of them as this would force the tasks to go back in the main thread. I prefer to do it this way because I'm using AWS lambda and I read somewhere that the lambda can freeze/terminated if the tasks stays in the background thread, see https://stackoverflow.com/a/39668749gildor
05/10/2019, 1:06 AMwithTimeoutOrNull(10000L) {
launch { s.deleteItem(xyz) }
launch { s.deleteItem(abc) }
}
runBlocking {
withTimeoutOrNull(10000L) {
launch(<http://Dispatchers.IO|Dispatchers.IO>) { s.deleteItem(xyz) }
launch(<http://Dispatchers.IO|Dispatchers.IO>) { s.deleteItem(abc) }
}
}
Hexa
05/10/2019, 8:46 AMgildor
05/10/2019, 3:34 PMHexa
05/13/2019, 12:46 PM