Colton Idle
03/25/2022, 9:15 PMFlowable
but that smells like hungarian notiation... but I do remember a book/blog post (effective java?) that said it should be clear when a method is doing stuff with threads/async.
Thoughts?
interface MyRepository {
suspend fun getLatestBooks(): List<Book>
fun getLatestBooksWithLiveUpdates(): Flow<List<Book>>
suspend fun getBookDetail(): BookDetail
fun getBookDetailWithLivesUpdates(): Flow<BookDetail>
}
Adam Powell
03/25/2022, 9:20 PMval latestBookLists: Flow<List<Book>>
, generally as properties instead of methods unless the flow needs to be recreated+parameterizedCasey Brooks
03/25/2022, 9:20 PMgetLatestBooksAsFlow()
, taking from the Compose convention of things like StateFlow.collectAsState()
.
Alternatively, you may consider only returning Flows
, not having any dedicated one-shot methods, and doing .first()
on those flows in place of the one-shot
methods (if your data sources allow for that, that is)Adam Powell
03/25/2022, 9:21 PMlatestBookLists.first()
is generally enough to not require a one-shot get method alongside it, but sometimes situational subscription overhead makes it suitable. If something can change such that you want a flow in some cases, it's also worth asking if exposing one-shot getters encourages weird race conditions somewhere. Often the answer is yes.Colton Idle
03/25/2022, 9:23 PMval latestBookLists: Flow<List<Book>>
somehow seems confusing to me. Maybe I gotta re-read it a bit more.
Wouldn't latestBooksLists
make more sense?
Basically when you land on my app you see a list of the top 10 books, and if a title change or something on the BE, then you see the update live.
Hence why I thought WithLiveUpdates
was kinda nice because it explains the intent a bit?Adam Powell
03/25/2022, 9:30 PMColton Idle
03/25/2022, 9:33 PMephemient
03/25/2022, 9:34 PMval latestBookss: Flow<List<Book>>
:android-badvice:Colton Idle
03/25/2022, 9:42 PMmyanmarking
03/25/2022, 10:46 PMColton Idle
03/25/2022, 10:47 PMmyanmarking
03/25/2022, 10:51 PMColton Idle
03/25/2022, 10:59 PMursus
03/27/2022, 9:05 AMloadFoo
for one time and foo
for flowK Merle
03/27/2022, 6:30 PMZoltan Demant
04/01/2022, 5:04 AMget -> T
query -> Flow<T>
Been doing this forever ā¤ļø Does it seem clear to you? It does to me, but I might just be super-used to it! šarty-parrot:Colton Idle
04/04/2022, 5:29 PMyeah,Can you expand on "sometimes situational subscription overhead makes it suitable" The way I initially read this was "there is more overhead to calling .first() on a flowable vs just having a one shot method available"is generally enough to not require a one-shot get method alongside it, but sometimes situational subscription overhead makes it suitable. If something can change such that you want a flow in some cases, it's also worth asking if exposing one-shot getters encourages weird race conditions somewhere. Often the answer is yes.latestBookLists.first()
Adam Powell
04/04/2022, 5:55 PM.first()
on a flowCancellationException
to stop the upstream after the first" to, "implementation of the specific flow sets up a two-way subscription over a long-running connection with a server instead of a much simpler REST request/response"Colton Idle
04/04/2022, 7:59 PM