https://kotlinlang.org logo
#coroutines
Title
# coroutines
j

jeggy

01/26/2023, 1:51 PM
Is it possible to find out which coroutine(s) were the reason for
withTimeout
throwing a
TimeoutCancellationException
?
s

Sam

01/26/2023, 2:05 PM
What do you mean by “which coroutine”? What information would you expect to get back that would let you identify a specific coroutine?
You could for example do this:
Copy code
val job = launch {
    doStuff()
}
select {
    job.onJoin { }
    onTimeout(1000) {
        job.children.forEach { job ->
            if (job.isActive) {
                println(job) // but is this helpful?
            }
        }
        job.cancel()
    }
}
but I don’t think it would be useful.
3 Views