I'm using a CoroutineWorker but all my business logic is a separate class which I start using a suspend function. I would prefer to keep all the logic in this class but I need to know if the work request has been canceled. Is there someway to know in the suspend function if it's been canceled?
Repeating gmk57's answer:
"Plain suspend
function (without withContext
) doesn't provide isActive
flag, but you can use coroutineContext.isActive
"
With a suspend function you do have access to your corountineContext
. Accessing that will give you access to all of the same properties that you can access from directly inside the context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With