rxjava : cold publisher, hot publisher
This commit is contained in:
13
RxJava/ReactiveStream/src/main/java/ColdPublisherEx.java
Normal file
13
RxJava/ReactiveStream/src/main/java/ColdPublisherEx.java
Normal file
@@ -0,0 +1,13 @@
|
||||
import io.reactivex.rxjava3.core.Flowable;
|
||||
|
||||
public class ColdPublisherEx {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Flowable<Integer> flowable = Flowable.just(1, 2, 3, 4);
|
||||
|
||||
// 구독시 처음부터 타임라인을 재구성하여 모든 데이터를 받을 수 있다.
|
||||
flowable.subscribe(data -> System.out.println("data = " + data));
|
||||
flowable.subscribe(data -> System.out.println("data = " + data));
|
||||
}
|
||||
}
|
||||
18
RxJava/ReactiveStream/src/main/java/HotPublisherEx.java
Normal file
18
RxJava/ReactiveStream/src/main/java/HotPublisherEx.java
Normal file
@@ -0,0 +1,18 @@
|
||||
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("subscribe1 = " + data));
|
||||
processor.onNext(1);
|
||||
processor.onNext(2);
|
||||
|
||||
// 구독한 시점 이후의 데이터만 받을 수 있다.
|
||||
processor.subscribe(data -> System.out.println("subscribe2 = " + data));
|
||||
processor.onNext(3);
|
||||
processor.onNext(4);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user