Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RxJava:顺序调用多个不相关的方法_Java_Rx Java - Fatal编程技术网

RxJava:顺序调用多个不相关的方法

RxJava:顺序调用多个不相关的方法,java,rx-java,Java,Rx Java,我在我的项目中使用RxJava,我有一种情况,两个方法一个接一个地被调用,并且都返回void。这些方法中的每一个都在内部使用RxJava 伪: void sendMsg_1() { ... //Fetch data from DB using RxJava to send message to client. .. } void sendMsg_2() { ... Uses RxJava to send message to client. .. } 调用代码: sendMsg_1(); s

我在我的项目中使用RxJava,我有一种情况,两个方法一个接一个地被调用,并且都返回void。这些方法中的每一个都在内部使用RxJava

伪:

void sendMsg_1() {
...
//Fetch data from DB using RxJava to send message to client.
..
}

void sendMsg_2() {
...
Uses RxJava to send message to client.
..
}
调用代码:

sendMsg_1();
sendMsg_2();
实际上,sendMsg_2更快,并且客户端在sendMsg_1发送其消息之前获得它。这对我不好,我希望Msg1的输出在Msg2之前发送

怎么做

我是否应该人工返回dummy observable,以便使用.flatMap,如下所示:

sendMsg_1()
.flatMap(msgObj-> { 
    return sendMsg_2();
}).subscribe();
有更好的办法吗


谢谢大家!

这是以rxJava的方式发出void方法的正确方式:

public rx.Completable func_A() {
    return Completable.create(subscriber -> {
        // func_A logic
        if(ok) subscriber.onCompleted();
        else subscriber.onError(throwable);
    });
}

func_A()
.doOnCompleted(() -> func_B())
.subscribe();

如果它能帮助任何人…享受:-)

唯一的问题是,你没有收到功能已完成的通知。你是什么意思?什么样的通知?问题是,我如何发出一个只有在所有可完成的完成后才会调用的可观察的通知?我尝试使用:“endWith()”,但没有产生正确的结果。对两个Completable使用
Completable.concat
,或者在第一个Completable上使用concatWith,然后呢?如何发射可见光?