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
usually when I want a list, I use a function returning a Flow followed by toList() which is working perfectly.
Here is what I write now:
interface UserRepo : CoroutineCrudRepository<User, Long> {
suspend fun findByEmail(email: String): User?
fun findByFirstName(firstName: String): Flow<User>
}
// in use:
val users = userRepo.findByFirstName("Max").toList() // toList() is the build-in suspended function
What about including this into the repository itself? Then the code is much cleaner and because toList() is a suspended function, the thread is not blocked anyways.
interface UserRepo : CoroutineCrudRepository<User, Long> {
suspend fun findByEmail(email: String): User?
suspend fun findByFirstName(firstName: String): List<User>
}
Currently an exception is thrown when I try the 2nd example.
The text was updated successfully, but these errors were encountered:
Sorry for the delay, supporting this kind of construct makes sense since it really depends on the use case for choosing between both and unlike Mono<List<User>>, the unwrapped version is pretty pleasant to use thanks to Coroutines. So +1 from my perspective.
Hello,
usually when I want a list, I use a function returning a
Flow
followed bytoList()
which is working perfectly.Here is what I write now:
What about including this into the repository itself? Then the code is much cleaner and because toList() is a suspended function, the thread is not blocked anyways.
Currently an exception is thrown when I try the 2nd example.
The text was updated successfully, but these errors were encountered: