dave08
10/29/2018, 12:34 PMcoroutineScope doesn't return until it completes... but then, I'd need to pass the CoroutineScope in download(scope: CoroutineScope)? That's a bit messy... and I can't even use a receiver since it's declared on another object... (unless I use with... 😒)marstran
10/29/2018, 12:34 PMJonathan
10/29/2018, 12:34 PMCoroutineScope.download() insteadmarstran
10/29/2018, 12:34 PMfun CoroutineScope.download() =.dave08
10/29/2018, 12:36 PMclient.download(url, it.sink, it.range).consumeEach { currBytes ->
val currTotal = totalDownloaded.addAndGet(currBytes)
i { "progress: $currTotal" }
progress.send(DownloadProgress.Downloading(currTotal, totalExpectedPartsSize))
}
Since client is the dependency where it's declared...dave08
10/29/2018, 12:37 PMwith(client) { download(...).consumeEach { ... } } 😛Jonathan
10/29/2018, 12:38 PMGlobalScope.produce. I think it is okay in this case, since you use consumeEach, the producer will anyway be cancelled if the consumer is cancelled or failed.dave08
10/29/2018, 12:41 PMGlobalScope? I guess it'll take a bit of time to get used to structured concurrency... but it's probably worth it 🙂dave08
10/29/2018, 2:05 PMwith(client) { download(...).consumeEach { ... } } gets VERY messy with Unit tests... 🙃marstran
10/29/2018, 2:07 PMclient as a normal parameter? download(client, ....).consumeEach { ... } }dave08
10/29/2018, 2:08 PMdownload is defined on client...dave08
10/29/2018, 2:08 PMdave08
10/29/2018, 2:09 PMwith just factors out the client receiver, allowing Kotlin to infer the CoroutineScope reciever.dave08
10/29/2018, 2:10 PMdave08
10/29/2018, 2:11 PMdave08
10/29/2018, 2:13 PMnulldev
10/29/2018, 3:46 PMClient not implement CoroutineScope?dave08
10/29/2018, 3:48 PMmarstran
10/29/2018, 5:19 PMclient.download(scope, ....). Having the scope as the receiver is just a convention.dave08
10/29/2018, 5:22 PMdownload... like I said, it comes out nicer in functional programming 🙂... but I think they should have some examples in the official docs that are not functional oriented...