I have Java TCP client Socket reading InputStream and distributing data packets to various parts of the application via RxJava PublishSubject. This works.
Also sometimes I write to OutputStream. Commands are converted into single data packet(byte[]) and pushed onto the stream. For this I use
public void writeToSocket(byte[] packet) {
Completable.fromAction(() -> {
outputStream.write(packet);
outputStream.flush();
}).subscribeOn(Schedulers.io()).subscribe();
}
Now I want to execute
outputStream.write(packet);
outputStream.flush();
in such a way that meets below condition
- Though source packet is getting created from multiple places (with different commands) simultaneously, execute above for each packet with a delay of 50 milliseconds. Ideally queue-up the packets and execute with delay.
Example:
Place1: createCommand1(),
Place2: createCommand1(), createCommand4()
Place3: createCommand1(), createCommand2(), .... createCommand10()
Is there any way to achieve this using RxJava. Thanks in advance!