https://kotlinlang.org logo
Title
j

jovmit

09/19/2018, 11:38 AM
I have a class that does file download. I have a function that triggers a download, and returns LiveData with the download progress. For each new call it would return new LiveData and it works nicely when I download 1 file. Now I want to launch new coroutine for each file download under the same scope, so I can cancel all at once if I want to. Can someone help with different ways to do this? or maybe what would be the best way? So I need to launch separate coroutine for each new call to the function, and add it under the same context.
g

gildor

09/19/2018, 11:46 AM
why do you need different way? just start coroutine for each download and control cancellation how you wish
j

jovmit

09/19/2018, 11:49 AM
maybe the question is a bit unclear. So the class extends the coroutine scope, and when I call
launch()
I am not sure if each launch is added in the scope (after the update to v23). then I could call
context.cancel()
to cancel everything under it
d

Daniel Tam

09/19/2018, 1:56 PM
correct, that should work