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

Andrew Gazelka

05/02/2021, 8:57 PM
Is there a way to get the job a SharedFlow is launched in? Basically, I want to do something like this
Copy code
// a method ...
val (sharedFlow, job) =  flow.shareIn(scope, SharingStarted.Eagerly)
jobs.add(job)
return sharedFlow
d

Dominaezzz

05/02/2021, 9:14 PM
What are you doing with
jobs
? You could maybe create a
CoroutineScope
just to share the flow and you would have a
Job
with a single
Job
child.
a

Andrew Gazelka

05/02/2021, 9:15 PM
jobs
is so I can cancel the flow
@Dominaezzz the point I am getting stuck at is creating the coroutine scope … with the default builder this is not possible afaik
oh wait I think I can just do `CoroutineScope()`… that’s easy
aha
d

Dominaezzz

05/03/2021, 9:32 AM
Ah, if it's for cancellation, you just definitely use a
scope
and
Job
then. Much easier imo.
4 Views