py
06/17/2021, 10:15 PMlouiscad
06/17/2021, 10:45 PMasCoroutineDispatcher()
on a Handler
instance, it's part of kotlinx-coroutines-android, I think the implementation it provides is correct for this edge case.py
06/19/2021, 2:42 PMlouiscad
06/19/2021, 2:45 PMZach Klippenstein (he/him) [MOD]
06/19/2021, 2:47 PMasCoroutineDispatcher
? I didn’t think the dispatch
method was allowed to throw, so the execution rejected exception approach wouldn’t work?py
06/19/2021, 5:11 PMIf the underlying executor throws RejectedExecutionException on attempt to submit a continuation task (it happens when closing the resulting dispatcher, on underlying executor shutdown, or when it uses limited queues), then the Job of the affected task is cancelled and the task is submitted to the Dispatchers.IO, so that the affected coroutine can cleanup its resources and promptly complete.
Do you want to send the PR, or should I do it?@louiscad you’re welcome to. This might be quite involved (look at the Executors impl), maybe worth filing an issue?