Created
June 27, 2017 01:49
-
-
Save natdempk/0d226f1e15bee697c231d0ee0d9d3484 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.common.collect.ImmutableList; | |
import io.reactivex.Observable; | |
import io.reactivex.schedulers.Schedulers; | |
import java.util.concurrent.ExecutionException; | |
import java.util.stream.Stream; | |
public class TestMain { | |
public static void main(String[] args) throws ExecutionException, InterruptedException { | |
Stream<Integer> ints = ImmutableList.of(1, 2, 3, 4, 5, 6) | |
.stream().map(i -> { | |
System.out.println("emitting:" + i); | |
return i; | |
}); | |
Long count = Observable.fromIterable(() -> ints.iterator()) | |
.observeOn(Schedulers.computation()) | |
.map(x -> x + 1) | |
.observeOn(Schedulers.io()) | |
.doOnNext(System.out::println) | |
.observeOn(Schedulers.computation()) | |
.count() | |
.blockingGet(); | |
System.out.println("count: " + count); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
emitting:1 | |
emitting:2 | |
emitting:3 | |
emitting:4 | |
2 | |
emitting:5 | |
emitting:6 | |
3 | |
4 | |
5 | |
6 | |
7 | |
count: 6 | |
Process finished with exit code 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment