want to ask one more thing, what would be the pref...
# coroutines
u
want to ask one more thing, what would be the preferred way to keep the job instances per each method? so I can cancel granularly?
g
Per each method? Just save job to some property
u
right, but scope already keeps that, should I mirror the map manually?
s
Each call to
launch
or
async
returns a
Job
, which you can cancel. The scope's Job is their parent-Job.
1
g
Scope doesn't keep reference on child jobs, it's opposite, child jobs are keeping reference on parent, so if you want to cancel them separately you should save them somehow. Tho, parent can cancel all child jobs together
a
@gildor does it really only child references a parent? Because I see that Job has "children" getter public val children: Sequence<Job> so also a parent must have references to all children (maybe not object references), but some kind of relationships exists in both directions
g
yeah, you right