You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know how to observe many downloads by ID. This is what I tried to do within my AndroidViewModel:
viewModelScope.launch {
val filesToDownload = loadDownloads()
filesToDownload.forEach { doc ->
val id = ketch.download(...)
viewModelScope.launch {
ketch.observeDownloadById(id)
.flowOn(Dispatchers.IO)
.collect { downloadModel ->
// Process the downloaded file if status == SUCCESS
if (downloadModel.status == Status.SUCCESS) {
Timber.d(downloadModel.url)
}
}
}
}
}
Function loadDownloads() is a suspend function which must run in its own IO coroutine. However, this approach does not work because I get multiple calls to the observe (probably due to the nested coroutines). If I omit the inner coroutine, it won't work either. The issue is, I must process each download right after the file is successfully downloaded. How do I solve this issue? Thank you so much.
The text was updated successfully, but these errors were encountered:
fun observeDownloads() {
list.forEach { // list of ids provided by ketch
viewModelScope.launch {
ketch.observeDownloadById(it).distinctUnitChanged().flowOn(Dispatchers.IO).collectLatest {
// here you can check when download is success.
}
}
}
}
another approach to observeAllDownloads at one place
fun observeAllDownloads() {
viewModelScope.launch {
ketch.observeAllDownloads().distinctUnitChanged().flowOn(Dispatchers.IO).collectLatest {
// here you will get complete downloads list, and you can do the pre processing
}
}
Also I will be publishing new version of ketch by this weekend, there I will be adding another method to observeDownloads by multiple Ids.
Thank you for this great library!
I don't know how to observe many downloads by ID. This is what I tried to do within my
AndroidViewModel
:Function
loadDownloads()
is a suspend function which must run in its own IO coroutine. However, this approach does not work because I get multiple calls to the observe (probably due to the nested coroutines). If I omit the inner coroutine, it won't work either. The issue is, I must process each download right after the file is successfully downloaded. How do I solve this issue? Thank you so much.The text was updated successfully, but these errors were encountered: