dimsuz
12/10/2021, 4:00 PMsuspend fun userList(): List<User>
fun userList(): Flow<List<User>>
Any idea on naming here, so that they don't conflict? in Rx we used to call the "blocking" one userListSync
, and "sync" were rare beasts actually. But in coroutine world calling suspend
function "sync" is not correct.userList().first()
, effectively removing the need for a separate suspending one, but this incurs setting up flow which in this case could be potenitally costlyJoffrey
12/10/2021, 4:02 PMdimsuz
12/10/2021, 4:02 PMFlow
oneJoffrey
12/10/2021, 4:03 PMfetchUserList()
for the one-shot, and just userList()
for the flowdimsuz
12/10/2021, 4:03 PMreadUserList()
maybeAdam Powell
12/10/2021, 4:05 PMdimsuz
12/10/2021, 4:06 PMuserLists(): Flow<List<User>>
?Adam Powell
12/10/2021, 4:06 PMuserLists
Casey Brooks
12/10/2021, 4:07 PMclass Query<T>(
private val liveQuery: Flow<T>,
private val defaultValue: T,
) {
fun asFlow(): Flow<T> {
return liveQuery
}
@Composable
fun asState(): State<T> {
return liveQuery.collectAsState(defaultValue)
}
suspend fun await(): T {
return liveQuery.first()
}
}
Joffrey
12/10/2021, 4:07 PMI find that using a plural for the flow tends to be more clear for a reader and avoids these conflictsThat's a fair point, but at the same time it can be confusing. It's hard to tell whether there are multiple lists of users, or whether the flow represents updates to the same list
Adam Powell
12/10/2021, 4:09 PMrudolf.hladik
12/13/2021, 8:26 AMgetUserList()
for suspend and observeUserList()
for flow, beacause you are basically observing changest to db