mirror of
https://github.com/OtusTeam/Spring.git
synced 2026-05-30 10:50:42 +00:00
36 lines
982 B
Java
36 lines
982 B
Java
package ru.otus;
|
|
|
|
import io.reactivex.Observable;
|
|
|
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
|
public class CreateExamples {
|
|
|
|
public static void main(String[] args) {
|
|
Observable<String> obs = justExample();
|
|
obs.forEach(System.out::println);
|
|
obs.forEach(System.out::println);
|
|
}
|
|
|
|
public static Observable<String> justExample() {
|
|
return Observable.just("one", "two", "three");
|
|
}
|
|
|
|
public static Observable<String> createExample() {
|
|
return Observable.create(emitter -> {
|
|
if (emitter.isDisposed()) {
|
|
return;
|
|
}
|
|
emitter.onNext("one");
|
|
emitter.onNext("two");//!
|
|
emitter.onNext("three");
|
|
if (!emitter.isDisposed()) {
|
|
emitter.onComplete();
|
|
}
|
|
});
|
|
}
|
|
|
|
public static Observable<String> deferExample() {
|
|
return Observable.defer(() -> Observable.just("one", "two", "three"));
|
|
}
|
|
}
|