#36 rxjava: hot, cold publisher
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
package org.example.ex03;
|
||||||
|
|
||||||
|
import io.reactivex.rxjava3.core.Flowable;
|
||||||
|
|
||||||
|
public class ColdPublisherEx {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Flowable<Integer> flowable = Flowable.just(1, 3, 5, 7);
|
||||||
|
|
||||||
|
flowable.subscribe(data -> System.out.println("구독자1: " + data));
|
||||||
|
flowable.subscribe(data -> System.out.println("구독자2: " + data));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package org.example.ex03;
|
||||||
|
|
||||||
|
import io.reactivex.rxjava3.processors.PublishProcessor;
|
||||||
|
|
||||||
|
public class HotPublisherEx {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
PublishProcessor<Integer> processor = PublishProcessor.create();
|
||||||
|
processor.subscribe(data -> System.out.println("구독자1: " + data));
|
||||||
|
processor.onNext(1);
|
||||||
|
processor.onNext(3);
|
||||||
|
|
||||||
|
processor.subscribe(data -> System.out.println("구독자2: " + data));
|
||||||
|
processor.onNext(5);
|
||||||
|
processor.onNext(7);
|
||||||
|
|
||||||
|
processor.onComplete();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user