I have a class that does file download. I have a f...
# coroutines
j
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
why do you need different way? just start coroutine for each download and control cancellation how you wish
j
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
correct, that should work