Ani Mehta
02/12/2020, 11:52 PMmon
02/13/2020, 12:08 AMZach Klippenstein (he/him) [MOD]
02/13/2020, 1:08 AMGlobalScope
if at all possible. Usually there is some concept of “lifetime” that surrounds where you’re launching coroutines from, so you can create a CoroutineScope
that represents that. Other than that, Mon’s solution is probably what I’d do.Zach Klippenstein (he/him) [MOD]
02/13/2020, 1:08 AMAni Mehta
02/13/2020, 1:10 AMval responses = needsResponses.map {
GlobalScope.async {
// get response
}
}
responses.map { it.await() }.map {
// process response
}
Ani Mehta
02/13/2020, 1:11 AMAni Mehta
02/13/2020, 1:20 AMneedsResponses
.map {
GlobalScope.async {
// get responses
}
}
.awaitAll()
.forEach {
// process responses
}
Zach Klippenstein (he/him) [MOD]
02/13/2020, 2:30 AMGlobalScope
lets you leak coroutines. It also makes it easier to refactor code without it being in the correct scope in its new location.Zach Klippenstein (he/him) [MOD]
02/13/2020, 2:30 AMken
02/13/2020, 10:15 PM