Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.x: Fix diamonds, spelling, unnecessary code #6804

Merged
merged 1 commit into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
30 changes: 15 additions & 15 deletions docs/Backpressure.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ The following diagrams show how you could use each of these operators on the bur
The `sample` operator periodically "dips" into the sequence and emits only the most recently emitted item during each dip:

<img src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/bp.sample.png" width="640" height="260" />​
````groovy
```java
Observable<Integer> burstySampled = bursty.sample(500, TimeUnit.MILLISECONDS);
````
```

### throttleFirst
The `throttleFirst` operator is similar, but emits not the most recently emitted item, but the first item that was emitted after the previous "dip":

<img src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/bp.throttleFirst.png" width="640" height="260" />​
````groovy
```java
Observable<Integer> burstyThrottled = bursty.throttleFirst(500, TimeUnit.MILLISECONDS);
````
```

### debounce (or throttleWithTimeout)
The `debounce` operator emits only those items from the source Observable that are not followed by another item within a specified duration:

<img src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/bp.debounce.png" width="640" height="240" />​
````groovy
```java
Observable<Integer> burstyDebounced = bursty.debounce(10, TimeUnit.MILLISECONDS);
````
```

## Buffers and windows

Expand All @@ -65,14 +65,14 @@ The following diagrams show how you could use each of these operators on the bur
You could, for example, close and emit a buffer of items from the bursty Observable periodically, at a regular interval of time:

<img src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/bp.buffer2.png" width="640" height="270" />​
````groovy
```java
Observable<List<Integer>> burstyBuffered = bursty.buffer(500, TimeUnit.MILLISECONDS);
````
```

Or you could get fancy, and collect items in buffers during the bursty periods and emit them at the end of each burst, by using the `debounce` operator to emit a buffer closing indicator to the `buffer` operator:

<img src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/bp.buffer1.png" width="640" height="500" />​
````groovy
```java
// we have to multicast the original bursty Observable so we can use it
// both as our source and as the source for our buffer closing selector:
Observable<Integer> burstyMulticast = bursty.publish().refCount();
Expand All @@ -87,16 +87,16 @@ Observable<List<Integer>> burstyBuffered = burstyMulticast.buffer(burstyDebounce
`window` is similar to `buffer`. One variant of `window` allows you to periodically emit Observable windows of items at a regular interval of time:

<img src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/bp.window1.png" width="640" height="325" />​
````groovy
```java
Observable<Observable<Integer>> burstyWindowed = bursty.window(500, TimeUnit.MILLISECONDS);
````

You could also choose to emit a new window each time you have collected a particular number of items from the source Observable:

<img src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/bp.window2.png" width="640" height="325" />​
````groovy
```java
Observable<Observable<Integer>> burstyWindowed = bursty.window(5);
````
```

# Callstack blocking as a flow-control alternative to backpressure

Expand All @@ -110,8 +110,8 @@ When you subscribe to an `Observable` with a `Subscriber`, you can request react

Then, after handling this item (or these items) in `onNext()`, you can call `request()` again to instruct the `Observable` to emit another item (or items). Here is an example of a `Subscriber` that requests one item at a time from `someObservable`:

````java
someObservable.subscribe(new Subscriber<t>() {
```java
someObservable.subscribe(new Subscriber<T>() {
@Override
public void onStart() {
request(1);
Expand All @@ -134,7 +134,7 @@ someObservable.subscribe(new Subscriber<t>() {
request(1);
}
});
````
```

You can pass a magic number to `request`, `request(Long.MAX_VALUE)`, to disable reactive pull backpressure and to ask the Observable to emit items at its own pace. `request(0)` is a legal call, but has no effect. Passing values less than zero to `request` will cause an exception to be thrown.

Expand Down
8 changes: 4 additions & 4 deletions docs/Combining-Observables.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ This section explains operators you can use to combine multiple Observables.

# Outline

- [`combineLatest`](#combineLatest)
- [`combineLatest`](#combinelatest)
- [`join` and `groupJoin`](#joins)
- [`merge`](#merge)
- [`mergeDelayError`](#mergeDelayError)
- [`mergeDelayError`](#mergedelayerror)
- [`rxjava-joins`](#rxjava-joins)
- [`startWith`](#startWith)
- [`switchOnNext`](#switchOnNext)
- [`startWith`](#startwith)
- [`switchOnNext`](#switchonnext)
- [`zip`](#zip)

## startWith
Expand Down
4 changes: 2 additions & 2 deletions docs/How-To-Use-RxJava.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ You use the Observable [`just( )`](http://reactivex.io/documentation/operators
Observable<String> o = Observable.from("a", "b", "c");

def list = [5, 6, 7, 8]
Observable<Integer> o = Observable.from(list);
Observable<Integer> o2 = Observable.from(list);

Observable<String> o = Observable.just("one object");
Observable<String> o3 = Observable.just("one object");
```

These converted Observables will synchronously invoke the [`onNext( )`](Observable#onnext-oncompleted-and-onerror) method of any subscriber that subscribes to them, for each item to be emitted by the Observable, and will then invoke the subscriber’s [`onCompleted( )`](Observable#onnext-oncompleted-and-onerror) method.
Expand Down
2 changes: 1 addition & 1 deletion docs/Writing-operators-for-2.0.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##### Table of contents

- [Introduction](#introduction)
- [Warning on internal components](warning-on-internal-components)
- [Warning on internal components](#warning-on-internal-components)
- [Atomics, serialization, deferred actions](#atomics-serialization-deferred-actions)
- [Field updaters and Android](#field-updaters-and-android)
- [Request accounting](#request-accounting)
Expand Down
36 changes: 12 additions & 24 deletions src/jmh/java/io/reactivex/rxjava3/core/BinaryFlatMapPerf.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,48 +86,42 @@ public void setup() {

singleFlatMapPublisher = Single.just(1).flatMapPublisher(new Function<Integer, Publisher<? extends Integer>>() {
@Override
public Publisher<? extends Integer> apply(Integer v)
throws Exception {
public Publisher<? extends Integer> apply(Integer v) {
return arrayFlowable;
}
});

singleFlatMapHidePublisher = Single.just(1).flatMapPublisher(new Function<Integer, Publisher<? extends Integer>>() {
@Override
public Publisher<? extends Integer> apply(Integer v)
throws Exception {
public Publisher<? extends Integer> apply(Integer v) {
return arrayFlowableHide;
}
});

singleFlattenAsPublisher = Single.just(1).flattenAsFlowable(new Function<Integer, Iterable<? extends Integer>>() {
@Override
public Iterable<? extends Integer> apply(Integer v)
throws Exception {
public Iterable<? extends Integer> apply(Integer v) {
return list;
}
});

maybeFlatMapPublisher = Maybe.just(1).flatMapPublisher(new Function<Integer, Publisher<? extends Integer>>() {
@Override
public Publisher<? extends Integer> apply(Integer v)
throws Exception {
public Publisher<? extends Integer> apply(Integer v) {
return arrayFlowable;
}
});

maybeFlatMapHidePublisher = Maybe.just(1).flatMapPublisher(new Function<Integer, Publisher<? extends Integer>>() {
@Override
public Publisher<? extends Integer> apply(Integer v)
throws Exception {
public Publisher<? extends Integer> apply(Integer v) {
return arrayFlowableHide;
}
});

maybeFlattenAsPublisher = Maybe.just(1).flattenAsFlowable(new Function<Integer, Iterable<? extends Integer>>() {
@Override
public Iterable<? extends Integer> apply(Integer v)
throws Exception {
public Iterable<? extends Integer> apply(Integer v) {
return list;
}
});
Expand All @@ -140,48 +134,42 @@ public Iterable<? extends Integer> apply(Integer v)

singleFlatMapObservable = Single.just(1).flatMapObservable(new Function<Integer, Observable<? extends Integer>>() {
@Override
public Observable<? extends Integer> apply(Integer v)
throws Exception {
public Observable<? extends Integer> apply(Integer v) {
return arrayObservable;
}
});

singleFlatMapHideObservable = Single.just(1).flatMapObservable(new Function<Integer, Observable<? extends Integer>>() {
@Override
public Observable<? extends Integer> apply(Integer v)
throws Exception {
public Observable<? extends Integer> apply(Integer v) {
return arrayObservableHide;
}
});

singleFlattenAsObservable = Single.just(1).flattenAsObservable(new Function<Integer, Iterable<? extends Integer>>() {
@Override
public Iterable<? extends Integer> apply(Integer v)
throws Exception {
public Iterable<? extends Integer> apply(Integer v) {
return list;
}
});

maybeFlatMapObservable = Maybe.just(1).flatMapObservable(new Function<Integer, Observable<? extends Integer>>() {
@Override
public Observable<? extends Integer> apply(Integer v)
throws Exception {
public Observable<? extends Integer> apply(Integer v) {
return arrayObservable;
}
});

maybeFlatMapHideObservable = Maybe.just(1).flatMapObservable(new Function<Integer, Observable<? extends Integer>>() {
@Override
public Observable<? extends Integer> apply(Integer v)
throws Exception {
public Observable<? extends Integer> apply(Integer v) {
return arrayObservableHide;
}
});

maybeFlattenAsObservable = Maybe.just(1).flattenAsObservable(new Function<Integer, Iterable<? extends Integer>>() {
@Override
public Iterable<? extends Integer> apply(Integer v)
throws Exception {
public Iterable<? extends Integer> apply(Integer v) {
return list;
}
});
Expand Down
30 changes: 15 additions & 15 deletions src/jmh/java/io/reactivex/rxjava3/core/CallableAsyncPerf.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void setup() {

Callable<Integer> c = new Callable<Integer>() {
@Override
public Integer call() throws Exception {
public Integer call() {
return 1;
}
};
Expand Down Expand Up @@ -120,71 +120,71 @@ public void subscribeOnFlowable(Blackhole bh) {
@Benchmark
public void observeOnFlowable(Blackhole bh) {
observeOnFlowable.subscribeWith(new PerfAsyncConsumer(bh)).await(1);
};
}

@Benchmark
public void pipelineFlowable(Blackhole bh) {
pipelineFlowable.subscribeWith(new PerfAsyncConsumer(bh)).await(1);
};
}

@Benchmark
public void subscribeOnObservable(Blackhole bh) {
subscribeOnObservable.subscribeWith(new PerfAsyncConsumer(bh)).await(1);
};
}

@Benchmark
public void observeOnObservable(Blackhole bh) {
observeOnObservable.subscribeWith(new PerfAsyncConsumer(bh)).await(1);
};
}

@Benchmark
public void pipelineObservable(Blackhole bh) {
pipelineObservable.subscribeWith(new PerfAsyncConsumer(bh)).await(1);
};
}

@Benchmark
public void observeOnSingle(Blackhole bh) {
observeOnSingle.subscribeWith(new PerfAsyncConsumer(bh)).await(1);
};
}

@Benchmark
public void subscribeOnSingle(Blackhole bh) {
subscribeOnSingle.subscribeWith(new PerfAsyncConsumer(bh)).await(1);
};
}

@Benchmark
public void pipelineSingle(Blackhole bh) {
pipelineSingle.subscribeWith(new PerfAsyncConsumer(bh)).await(1);
};
}

@Benchmark
public void observeOnCompletable(Blackhole bh) {
observeOnCompletable.subscribeWith(new PerfAsyncConsumer(bh)).await(1);
};
}

@Benchmark
public void subscribeOnCompletable(Blackhole bh) {
subscribeOnCompletable.subscribeWith(new PerfAsyncConsumer(bh)).await(1);
};
}

@Benchmark
public void pipelineCompletable(Blackhole bh) {
pipelineCompletable.subscribeWith(new PerfAsyncConsumer(bh)).await(1);
};
}

@Benchmark
public void observeOnMaybe(Blackhole bh) {
observeOnMaybe.subscribeWith(new PerfAsyncConsumer(bh)).await(1);
};
}

@Benchmark
public void subscribeOnMaybe(Blackhole bh) {
subscribeOnMaybe.subscribeWith(new PerfAsyncConsumer(bh)).await(1);
};
}

@Benchmark
public void pipelineMaybe(Blackhole bh) {
pipelineMaybe.subscribeWith(new PerfAsyncConsumer(bh)).await(1);
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ public void nbpRangeMapRange(Blackhole bh) {

@Benchmark
public void singleJust(Blackhole bh) {
singleJust.subscribe(new LatchedSingleObserver<Integer>(bh));
singleJust.subscribe(new LatchedSingleObserver<>(bh));
}

@Benchmark
public void singleJustMapJust(Blackhole bh) {
singleJustMapJust.subscribe(new LatchedSingleObserver<Integer>(bh));
singleJustMapJust.subscribe(new LatchedSingleObserver<>(bh));
}
}
4 changes: 2 additions & 2 deletions src/jmh/java/io/reactivex/rxjava3/core/FlatMapJustPerf.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public void setup() {

flowable = Flowable.fromArray(array).flatMap(new Function<Integer, Publisher<Integer>>() {
@Override
public Publisher<Integer> apply(Integer v) throws Exception {
public Publisher<Integer> apply(Integer v) {
return Flowable.just(v);
}
});

observable = Observable.fromArray(array).flatMap(new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer v) throws Exception {
public Observable<Integer> apply(Integer v) {
return Observable.just(v);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public void setup() {

flowable = Flowable.fromArray(array).flatMapIterable(new Function<Integer, Iterable<Integer>>() {
@Override
public Iterable<Integer> apply(Integer v) throws Exception {
public Iterable<Integer> apply(Integer v) {
return list;
}
});

observable = Observable.fromArray(array).flatMapIterable(new Function<Integer, Iterable<Integer>>() {
@Override
public Iterable<Integer> apply(Integer v) throws Exception {
public Iterable<Integer> apply(Integer v) {
return list;
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/jmh/java/io/reactivex/rxjava3/core/FlattenJustPerf.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public void setup() {

flowable = Flowable.fromArray(array).flatMapIterable(new Function<Integer, Iterable<Integer>>() {
@Override
public Iterable<Integer> apply(Integer v) throws Exception {
public Iterable<Integer> apply(Integer v) {
return singletonList;
}
});

observable = Observable.fromArray(array).flatMapIterable(new Function<Integer, Iterable<Integer>>() {
@Override
public Iterable<Integer> apply(Integer v) throws Exception {
public Iterable<Integer> apply(Integer v) {
return singletonList;
}
});
Expand Down
Loading