Don Mitchell
04/30/2025, 8:22 PM>>
designates where I expect it to void the supervisorScope
. (Are there paradigmatic examples of how to void the supervisorScope
?)
supervisorScope {
accounts.forEach { account ->
this.ensureActive()
launch(errorHandler("..")) {
doit(account)
}
}
}
protected fun errorHandler(msg: String): CoroutineExceptionHandler =
CoroutineExceptionHandler { context, exception ->
logger.error(exception) { msg }
if (exception.fatal() || exception.outOfDiskSpace()) {
>> context.cancel(CancellationException(null, cause = exception))
}
}
ephemient
04/30/2025, 8:33 PMcontext
and it's already dead by the time your CEH runs, so context.cancel()
does nothingDon Mitchell
04/30/2025, 8:40 PMsupervisorScope
? In other places I use the following, do they work?
supervisorScope {
accounts.forEach { account ->
this.ensureActive()
launch(errorHandler("..")) {
try {
doit(account)
} catch (e: Exception) {
if (e.fatal() || e.outOfDiskSpace()) {
this@supervisorScope.cancel("Fatal", e)
} else { throw e }
}
}
}
}
ephemient
04/30/2025, 8:41 PMephemient
04/30/2025, 8:44 PMcoroutineScope {
accounts.forEach { account ->
this.ensureActive()
launch {
try {
doit(account)
} catch (exception: Exception) {
if (exception.fatal() || exception.outOfDiskSpace()) {
throw exception
}
// swallow exception
}
}
}
}
Don Mitchell
04/30/2025, 8:46 PMtry/catch
in place of supervisorScope
may be better, but why doesn't supervisorScope
have an override? It's rather dangerous that OOM and other fatal exceptions get swallowed imhoephemient
04/30/2025, 8:51 PM