T
T
TikTak12362018-08-07 18:30:41
Android
TikTak1236, 2018-08-07 18:30:41

What is the best way to make two requests with RxJava?

I need to implement registration, authorization in the application, and after successful registration, I need to log in. For network request I use Retrofit. How can I better implement using chains in RxJava or without or what is the best, please recommend.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Emelyanov, 2018-08-09
@MAGISTR_BRU

//Функция регистрации
fun registration(args: Array<String>) {
    compositeDisposable.add(
        retofit.registrate(args)
        .subscribe({
            //User successful registered
            //Do auth
            authorization(args)
        }, {
            handleError(it)
        })
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
    )
}

//Функция авторизации
fun authorization(args: Array<String>) {
    compositeDisposable.add(
        retofit.auth(args)
        .subscribe({
            //User successful auth
            //Do work after user auth
            userSuccessfulAuth()
        }, {
            handleError(it)
        })
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
    )
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question