Ждите ответа RxJava - PullRequest
       16

Ждите ответа RxJava

1 голос
/ 09 октября 2019

Подумайте об этом func1 () в другом Java-классе, вы можете связаться с ним по обратному вызову. Моя проблема в том, что я хочу дождаться результата func1. Как я могу это сделать?

launch{
    func1()

    func2()
    func3()

    // I want to catch the data here, so it should wait here but because of using rxjava (another thread), I cannot control it. 
    // I know if I use new retrofit libs, I can use coroutines, but right now, I cannot change old ones. 

    //My problem is I want to wait the func1 result here. How can I do that?
}

suspend fun func2(){}
suspend fun func3(){}

//Another java class
public Single<MyData> func1(){
    apiClient.getMyData()
    .subscribe(myData -> {
        // Let's say this takes 5 seconds to get the data
    }, throwable -> {

    });
}

1 Ответ

1 голос
/ 09 октября 2019

Добавить библиотеку

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-rx2:$coroutine_version"

Затем позвоните,

func1().await()

Подробнее здесь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...