如何链接多个主题?

时间:2018-09-22 02:43:26

标签: rx-java reactive-programming behaviorsubject

我是RXJava的新手。 我有几个任务要按顺序处理。

BehaviorSubject<String> task1 = BehaviorSubject.create();
BehaviorSubject<String> task2 = BehaviorSubject.create();
BehaviorSubject<String> task3 = BehaviorSubject.create();

/* SUBSCRIBING */
task1.doOnNext(s -> System.out.print(" task1")).subscribe(s -> task2.onNext(s));
task2.doOnNext(s -> System.out.print(" task2")).subscribe(s -> task3.onNext(s));
task3.doOnNext(s -> System.out.println(" task3")).subscribe();

task1.onNext("");
task2.onNext(""); // insert data to start from task2
task3.onNext(""); // insert data to start from task3

是否可以使用Rx API将SUBSCRIBING部分划分为一行?

0 个答案:

没有答案