I use RxJava in my project and I have a situation where 2 methods are called one after the other and both return void. Each of these methods internally use RxJava.
Pseudo:
void sendMsg_1() {
...
//Fetch data from DB using RxJava to send message to client.
..
}
void sendMsg_2() {
...
Uses RxJava to send message to client.
..
}
Invoking code:
sendMsg_1();
sendMsg_2();
Practically, sendMsg_2 is faster and client gets it before sendMsg_1 sends his msg. This is not good for me and I would like output of Msg1 be sent before Msg2.
How to do it?
Should I artificially return dummy observable just so I can use .flatMap as follow:
sendMsg_1()
.flatMap(msgObj-> {
return sendMsg_2();
}).subscribe();
Is there a better way?
Thank you!