is, here.
You can follow the steps inside the deprecation warning to see your alternatives. You can even auto-fix this problem with the IDE.
t
Tower Guidev2
04/29/2022, 12:55 PM
cheers @Stylianos Gakis
a common mistake
...I Had found
yield()
which seemed to do the trick, is that wrong?
s
Stylianos Gakis
04/29/2022, 1:03 PM
Hm that should work as well, it does check for cancellation.
It’s just that yield() as I understand it does more than just that as indicated by its documentation. Something about giving a chance for other coroutines in the same dispatcher to run. While
currentCoroutineContext().isActive
will just check for cancellation.
This might matter if you somehow rely on that piece of code not suspending to wait for something else. Practically speaking, in like 99% of the use cases my guess is that it doesn’t matter though 😅 If some coroutine expert would like to chime in to say why I’m wrong I’d love to hear it
🙌 1
t
Tower Guidev2
04/29/2022, 1:07 PM
thanks for the detail
im using
yield()
in my Andriod background workers,
androidx.work.CoroutineWorker
, so from what you are saying i am good
if i understand correctly 😄
s
Stylianos Gakis
04/29/2022, 1:13 PM
I haven’t used a
CoroutineWorker
before, but yes, yield() does check for cancellation so you’re good 😄