bbaldino
12/01/2020, 6:33 PMval t = scope.async { ... }
val u = scope.async { ... }
try {
select<Unit> {
t.onAwait { ... }
u.onAwait { ... }
}
} catch (c: CancellationException) {
...
} catch (t: Throwable) {
...
}
where scope is not cancelled anywhere and one of the t, u tasks throws an exception, should I always be able to catch the exception that was thrown in my block? I'm seeing that most of the time I get the exception thrown by t or u, but sometimes I get a CancellationException wrapping the exception thrown by t or u and I'm trying to figure out if this is to be expected when using select or if I'm doing something wrong.bezrukov
12/01/2020, 6:37 PMscope that means if any of your async blocks fails, another will be cancelled as well. If you will switch to SupervisorJob another async won't be cancelledbbaldino
12/01/2020, 6:38 PMbbaldino
12/01/2020, 6:42 PMCancellationExceptionbezrukov
12/01/2020, 6:44 PMprivate val scope = CoroutineScope(SupervisorJob()+CoroutineName("FileRecordingService")) you will catch only error from tbbaldino
12/01/2020, 6:45 PMbbaldino
12/01/2020, 6:45 PMbezrukov
12/01/2020, 6:46 PMbbaldino
12/01/2020, 6:46 PMbbaldino
12/01/2020, 6:51 PMbezrukov
12/01/2020, 7:21 PMtry {
coroutineScope {
async { // t code }
async { // u code }
}
} catch (e: ...) {
}bezrukov
12/01/2020, 7:21 PMbbaldino
12/01/2020, 7:24 PMbezrukov
12/01/2020, 7:24 PMbbaldino
12/01/2020, 7:25 PMbezrukov
12/01/2020, 7:25 PMbezrukov
12/01/2020, 7:26 PMbbaldino
12/01/2020, 7:26 PMbezrukov
12/01/2020, 7:27 PMbbaldino
12/01/2020, 7:27 PMcoroutineScope behavior (wait for all children to finish) within the scope of an explicit CoroutineScope ? (e.g. the scope member of that class)bezrukov
12/01/2020, 7:28 PMbbaldino
12/01/2020, 7:29 PMcoroutineScope scope and join it in the scope scope?bezrukov
12/01/2020, 7:29 PMbbaldino
12/01/2020, 7:42 PMscope.launch {
try {
coroutineScope {
launch { ... }
launch { ... }
}
} catch (...) {
}
}.join()bbaldino
12/01/2020, 7:42 PMscope so that I can have a stop method in the class which can call cancel on scopebbaldino
12/01/2020, 8:52 PMbezrukov
12/01/2020, 9:19 PMbbaldino
12/01/2020, 9:20 PM