Skip to content

Commit a1e634b

Browse files
Viktor SchmidtViktor Schmidt
authored andcommitted
upgrade to rxjava2
1 parent d2c6c09 commit a1e634b

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/main/java/learnrxjava/examples/FlowControlThrottleExample.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
package learnrxjava.examples;
22
import java.util.concurrent.TimeUnit;
33

4-
import rx.Observable;
5-
import rx.Subscriber;
6-
import rx.schedulers.Schedulers;
4+
import io.reactivex.Observable;
5+
import io.reactivex.ObservableEmitter;
6+
import io.reactivex.schedulers.Schedulers;
7+
8+
79

810
public class FlowControlThrottleExample {
911

1012
public static void main(String args[]) {
1113
// first item emitted in each time window
12-
hotStream().throttleFirst(500, TimeUnit.MILLISECONDS).take(10).toBlocking().forEach(System.out::println);
14+
hotStream().throttleFirst(500, TimeUnit.MILLISECONDS).take(10).blockingForEach(System.out::println);
1315

1416
// last item emitted in each time window
15-
hotStream().throttleLast(500, TimeUnit.MILLISECONDS).take(10).toBlocking().forEach(System.out::println);
17+
hotStream().throttleLast(500, TimeUnit.MILLISECONDS).take(10).blockingForEach(System.out::println);
1618
}
1719

1820
/**
1921
* This is an artificial source to demonstrate an infinite stream that emits randomly
2022
*/
2123
public static Observable<Integer> hotStream() {
22-
return Observable.create((Subscriber<? super Integer> s) -> {
24+
return Observable.create((ObservableEmitter<Integer> s) -> {
2325
int i = 0;
24-
while (!s.isUnsubscribed()) {
26+
while (!s.isDisposed()) {
2527
s.onNext(i++);
2628
try {
2729
// sleep for a random amount of time

src/main/java/learnrxjava/examples/FlowControlWindowExample.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22

33
import java.util.concurrent.TimeUnit;
44

5-
import rx.Observable;
6-
import rx.Subscriber;
7-
import rx.schedulers.Schedulers;
5+
import io.reactivex.Observable;
6+
import io.reactivex.ObservableEmitter;
7+
import io.reactivex.schedulers.Schedulers;
8+
9+
810

911
public class FlowControlWindowExample {
1012

1113
public static void main(String args[]) {
1214
// buffer every 500ms (using 999999999 to mark start of output)
13-
hotStream().window(500, TimeUnit.MILLISECONDS).take(10).flatMap(w -> w.startWith(999999999)).toBlocking().forEach(System.out::println);
15+
hotStream().window(500, TimeUnit.MILLISECONDS).take(10).flatMap(w -> w.startWith(999999999)).blockingForEach(System.out::println);
1416

1517
// buffer 10 items at a time (using 999999999 to mark start of output)
16-
hotStream().window(10).take(2).flatMap(w -> w.startWith(999999999)).toBlocking().forEach(System.out::println);
18+
hotStream().window(10).take(2).flatMap(w -> w.startWith(999999999)).blockingForEach(System.out::println);
1719

1820
System.out.println("Done");
1921
}
@@ -22,8 +24,8 @@ public static void main(String args[]) {
2224
* This is an artificial source to demonstrate an infinite stream that bursts intermittently
2325
*/
2426
public static Observable<Integer> hotStream() {
25-
return Observable.create((Subscriber<? super Integer> s) -> {
26-
while (!s.isUnsubscribed()) {
27+
return Observable.create((ObservableEmitter<Integer> s) -> {
28+
while (!s.isDisposed()) {
2729
// burst some number of items
2830
for (int i = 0; i < Math.random() * 20; i++) {
2931
s.onNext(i);

0 commit comments

Comments
 (0)