RxJava with Java 8 Stream

Below is example to use JDK 8 stream with RxJava Observable.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

import io.reactivex.Observable;
import io.reactivex.functions.Consumer;

public class DemoRxJava {
public static void main(String[] args) throws InterruptedException {
Stream<Date> dates = Stream.generate(Date::new);
Consumer<Date> consumer = System.out::println;
Observable<Date> observable = Observable.fromIterable(() -> {
return dates.iterator();
});
System.out.println("Waiting..............");
TimeUnit.MINUTES.sleep(1);
System.out.println("Start.............");
observable.subscribe(consumer);
}
}

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *