https://kotlinlang.org logo
Title
d

dave08

12/17/2018, 1:41 PM
I have a callback receiving progress on downloading part of a file, I want to accumulate the progress of all the parts being downloaded to show progress in an Android app, do I really need that channel to send the results? Is there any better way to accumulate these results with a channel (maybe without the AtomicLong)?
g

gildor

12/17/2018, 3:43 PM
I just use callbacks for that
d

dave08

12/17/2018, 3:45 PM
Problem is that I need to accumulate the progress from the
async
downloads (each one is downloading a different part into a seperate file)... so there's race conditions...
g

gildor

12/17/2018, 3:47 PM
Yeah, I see. AtomicLong is actually fine solution. Channel does a few atomic operations and a few objects on each emit so probably AtomicLong + call back is fine
d

dave08

12/17/2018, 3:50 PM
My problem is (1) unit testing which is VERY painful with this.. and (2) a mysterious extra value slips in (maybe a problem in my unit tests... or maybe just the time between the offer and the addAndGet...). I think the standard way in the coroutine guide is just to pass the same channel to all the
async
downloads.