Closed CarsonRedeye closed 4 years ago
Hi! Thank you for this info! As you seem to have a good understanding of this gotcha, I would really appreciate it if you could submit a PR with some comments in the workmanager use case so that people don't make the same mistake as you.
Sure will do
Here's something that caught me out while using WorkManager with coroutines that you might want to add: Do not call a suspend function in the catch block (when you are trying to set the action as failed in the database etc). It will not be called when the work is cancelled due to system constraints. In that case WorkManager will throw JobCancellationException which means suspend functions will re-throw immediately. If you really want the suspend function to run, you must use NonCancellable context. See: https://kotlinlang.org/docs/reference/coroutines/cancellation-and-timeouts.html#run-non-cancellable-block