https://kotlinlang.org logo
#android
Title
# android
m

Marcelo Hernandez

03/23/2020, 10:57 PM
Not sure if this has been asked before but upon looking at the source code of
CoroutineWorker#startWork
, it seems it doesn't take
CancellationException
into account. It catches
Throwable
and sets the exception on the future.
Copy code
@Suppress("DEPRECATION")
    final override fun startWork(): ListenableFuture<Result> {

        val coroutineScope = CoroutineScope(coroutineContext + job)
        coroutineScope.launch {
            try {
                val result = doWork()
                future.set(result)
            } catch (t: Throwable) {
                future.setException(t)
            }
        }

        return future
    }
Should implementations of
doWork()
have to handle
CancellationException
themselves?