#36 rxjava: hot, cold publisher

This commit is contained in:
haerong22
2023-04-19 23:36:54 +09:00
parent f78db7e5c9
commit 4cb96ac29c
2 changed files with 32 additions and 0 deletions

View File

@@ -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));
}
}

View File

@@ -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();
}
}