Android number with RxJava processes empty query result

Trying to test new Android Room library with RxJava adapter. And I want to process the result if my query returns 0 objects from the database:

So here is the DAO method:

@Query("SELECT * FROM auth_info")
fun getAuthInfo(): Flowable<AuthResponse>

And how I process it:

        database.authDao().getAuthInfo()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .switchIfEmpty { Log.d(TAG, "IS EMPTY") }
            .firstOrError()
            .subscribe(
                    { authResponse -> Log.d(TAG, authResponse.token) },
                    { error -> Log.d(TAG, error.message) })

My database is empty, so I expect .switchIfEmty () to work, but none of the processing methods fire. Neither .subscribe () nor .switchIfEmpty ()

+4
source share
3 answers

Db Flowables ( , ), . List<AuthResponse>. , , . , , .

+4

1.0.0-alpha5 ​​ Maybe Single DAO, -

@Query("SELECT * FROM auth_info")
fun getAuthInfo(): Maybe<AuthResponse>

+2

switchIfEmpty a Publisher<AuthResponse>. SAM- . , Publisher, .

, Flowable.empty().doOnSubscribe { Log.d(TAG, "IS EMPTY") }, .

0
source

Source: https://habr.com/ru/post/1678023/


All Articles