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

Mark

05/03/2020, 9:53 AM
Are there any best practices for using/calling coroutines from an Android ContentProvider? I’m thinking in terms of CoroutineScopes and contentprovider lifecycle, etc.
l

louiscad

05/03/2020, 10:03 AM
runBlocking. The scope of a ContentProvider is either a call to one of its function, or the app process depending on what you want to do.
m

Mark

05/03/2020, 10:10 AM
Ok thanks Louis. How about the shutdown() implementation. Anything to think about there?
w

wasyl

05/03/2020, 11:29 AM
If you use
runBlocking
then there’s nothing to release in
shutdown
from what I understand
👍 2
l

louiscad

05/03/2020, 7:18 PM
From the docs (https://developer.android.com/reference/kotlin/android/content/ContentProvider#shutdown), the
shutdown
method is only ever called in unit testing. If you're unit testing your
ContentProvider
and use something other than
runBlocking
, you can cancel your custom
CoroutineScope
in this callback.
👍 1
m

Mark

05/05/2020, 3:15 AM
How about the CancellationSignal? Instead of passing that through the suspend functions (and checking it in loops, for example), is there a better way?
6 Views