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

Paul Woitaschek

11/06/2018, 12:23 PM
How do you pass the
CoroutineContext
when it's defined as the receiver on a supsending function inside a class?
z

Zach Klippenstein (he/him) [MOD]

11/06/2018, 6:07 PM
Couple things: 1.
CoroutineContext
as a receiver is odd, normally
CoroutineScope
is used as a receiver type. 2. Suspending functions shouldn’t have
CoroutineScope
receivers. If they need access to the current scope they should use the
coroutineScope
function. If you want to make it possible to add additional context, pass a
CoroutineContext
as a normal argument to your method (that’s how all the standard builders like
launch
,
async
, etc work).
p

Paul Woitaschek

11/06/2018, 6:38 PM
Yep, I meant to write
CoroutineContext
, thanks.
2 Views