Hi all, when using workmanager, how could we liste...
# coroutines
b
Hi all, when using workmanager, how could we listen when worker is stopped within the worker ?
n
Assuming you are talking about CoroutineWorker. If the coroutine is cancelled, then a
CancellationException
will be thrown from suspending methods.
Copy code
override suspend fun doWork(): Result {
    try {
        doStuffInSuspendMethod()
        return Result.success()
    } catch (ce: CancellationException) {
        handleCancellationSpecifically()
        throw ce
    }
}
I rarely need to do anything in response to cancellation specifically and usually just use a finally block. There's also
isActive
property on
CoroutineScope
and
CoroutineContext
.
b
thank you, i only see
isStopped