I have a callback receiving progress on downloadin...
# coroutines
d
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
I just use callbacks for that
d
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
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
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.