Tim Malseed
07/16/2020, 6:29 AMoverride fun loadData() {
launch {
songRepository.getSongs(SongQuery.Album(name = album.name, albumArtistName = album.albumArtist))
.collect { songs ->
this@AlbumDetailPresenter.songs = songs
view?.setData(songs)
}
}
}
But this doesn’t:
override fun loadData() {
launch {
songRepository.getSongs(SongQuery.Album(name = album.name, albumArtistName = album.albumArtist))
.collect { songs ->
this@AlbumDetailPresenter.songs = songs
}
view?.setData(songs)
}
}
view?.setData(songs)
only get called after collect {}
has completed?octylFractal
07/16/2020, 6:31 AMTim Malseed
07/16/2020, 6:32 AMoctylFractal
07/16/2020, 6:32 AMview
is non-null?Tim Malseed
07/16/2020, 6:32 AMview?.setData(songs)
is not called (breakpoint not hit in debugger) - even if view
was null I’d still expect the line to be hitoctylFractal
07/16/2020, 6:33 AMgildor
07/16/2020, 6:33 AMoctylFractal
07/16/2020, 6:33 AMgildor
07/16/2020, 6:34 AMTim Malseed
07/16/2020, 6:34 AMgildor
07/16/2020, 6:34 AMTim Malseed
07/16/2020, 6:35 AMgildor
07/16/2020, 6:36 AMTim Malseed
07/16/2020, 6:36 AMcollect
will complete for streams is a good lessongildor
07/16/2020, 6:39 AMsongRepository.getSongs(...)
.onEach { setData(it) }
.launchIn(scope)
Tim Malseed
07/16/2020, 6:40 AMlaunch {
flow.collect {
}
doSomething()
}
gildor
07/16/2020, 6:42 AMTim Malseed
07/16/2020, 6:44 AMgildor
07/16/2020, 6:44 AMTim Malseed
07/16/2020, 6:44 AMgildor
07/16/2020, 6:46 AMTim Malseed
07/16/2020, 6:46 AMgildor
07/16/2020, 6:58 AMTim Malseed
07/16/2020, 6:59 AMoctylFractal
07/16/2020, 6:59 AMMono
in rxgildor
07/16/2020, 6:59 AMTim Malseed
07/16/2020, 7:00 AMgildor
07/16/2020, 7:01 AMif you need intermediate emissions before completionWhat do you mean?
Tim Malseed
07/16/2020, 7:02 AMoctylFractal
07/16/2020, 7:02 AM0..N
gildor
07/16/2020, 7:03 AMoctylFractal
07/16/2020, 7:03 AMgildor
07/16/2020, 7:04 AMwhich implies aThis is the same what Flow or rxjava Observable or Flux is and it exactly the same problem0..N
julian
07/16/2020, 7:05 AMTim Malseed
07/16/2020, 7:10 AMgildor
07/16/2020, 7:11 AMTim Malseed
07/16/2020, 7:12 AMgildor
07/16/2020, 7:13 AMTim Malseed
07/16/2020, 7:14 AMoctylFractal
07/16/2020, 7:14 AMdelay(Long.MAX_VALUE)
gildor
07/16/2020, 7:15 AMTim Malseed
07/16/2020, 7:18 AMoctylFractal
07/16/2020, 7:18 AMTim Malseed
07/16/2020, 7:18 AMoctylFractal
07/16/2020, 7:19 AMTim Malseed
07/16/2020, 7:19 AMgildor
07/16/2020, 7:19 AMTim Malseed
07/16/2020, 7:20 AMgildor
07/16/2020, 7:21 AMTim Malseed
07/16/2020, 7:22 AMalbertosh
07/16/2020, 7:30 AMTim Malseed
07/16/2020, 7:32 AMonCompletion()
- without looking at the stream, you don’t know whether this will ever be called.albertosh
07/16/2020, 7:33 AMTim Malseed
07/16/2020, 7:33 AMalbertosh
07/16/2020, 7:33 AMTim Malseed
07/16/2020, 7:36 AMalbertosh
07/16/2020, 7:36 AMfilesInFolder
method I know for sure that it will finish in a reasonable amount of time
databaseChanges
will never finish (unless the app gets closed and some cleanup needs to be done)
time
(not sure why, but just as an example) will be there foreverTim Malseed
07/16/2020, 7:37 AMCompletableFlow
was just a Flow
with a different name, then you may as well just rename the variable/function.albertosh
07/16/2020, 7:40 AMwhile(true)
in imperative programming, any developer with the asynchronous model in the head should not rely on putting anything after a collect
typealias CompletableFlow<T> = Flow<T>
fun listFiles(): CompletableFlow<T>
But, otherwise, everything is the sameTim Malseed
07/16/2020, 7:42 AMonComplete()
. But yeah, you have to have the expectation that it may never be calledalbertosh
07/16/2020, 7:48 AMCompletableFlow
you could go for an inline class
inline class CompletableFlow<T>(private val flow: Flow<T>)
So you can have functions that only accept a CompletableFlow
val flow: Flow<Int> = ...
val completable: CompletableFlow<Int> = ...
fun demo(c: CompletableFlow<Int>) = ...
demo(completable) // works
demo(flow) // doesn't work
I’m not sure about inline classes and generics, thoughjulian
07/16/2020, 7:56 AMZach Klippenstein (he/him) [MOD]
07/16/2020, 2:22 PMNow, I know you want to ask: How would one indicate this behaviour?I think this would be a great use case for dependent types, which kotlin doesn't have and probably never will. https://en.m.wikipedia.org/wiki/Dependent_type
gildor
07/16/2020, 2:25 PMZach Klippenstein (he/him) [MOD]
07/16/2020, 2:29 PMgildor
07/16/2020, 2:36 PMZach Klippenstein (he/him) [MOD]
07/16/2020, 2:45 PMTim Malseed
07/16/2020, 3:12 PM