-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for parallelFlowable * Change Readme to mention support for parallelFlowable as well * Add Kotlin tests * Fix docs for parallelFlowable * Fix checkStyle errors * Fix nitpicks * Validate subscribers and replace to() with as() Summary: Added the missing check in subscribe method which checks if parallelism == subscribers.count(). Also replaced ParallelFlowableScoper with AutoDisposeParallelFlowableConverter. * Rename ParallelFlowableConverter to ParallelFlowableScoper
- Loading branch information
1 parent
75f2808
commit 13a6b57
Showing
8 changed files
with
616 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
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
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
52 changes: 52 additions & 0 deletions
52
autodispose/src/main/java/com/uber/autodispose/ParallelFlowableScoper.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.uber.autodispose; | ||
|
||
import org.reactivestreams.Subscriber; | ||
|
||
import io.reactivex.Maybe; | ||
import io.reactivex.parallel.ParallelFlowable; | ||
import io.reactivex.parallel.ParallelFlowableConverter; | ||
|
||
class ParallelFlowableScoper<T> extends Scoper | ||
implements ParallelFlowableConverter<T, ParallelFlowableSubscribeProxy<T>> { | ||
|
||
ParallelFlowableScoper(Maybe<?> scope) { | ||
super(scope); | ||
} | ||
|
||
@Override public ParallelFlowableSubscribeProxy<T> apply(final ParallelFlowable<T> upstream) { | ||
return new ParallelFlowableSubscribeProxy<T>() { | ||
@Override public void subscribe(Subscriber<? super T>[] subscribers) { | ||
new AutoDisposeParallelFlowable<>(upstream, scope()).subscribe(subscribers); | ||
} | ||
}; | ||
} | ||
|
||
static final class AutoDisposeParallelFlowable<T> extends ParallelFlowable<T> { | ||
|
||
private final ParallelFlowable<T> source; | ||
private final Maybe<?> scope; | ||
|
||
AutoDisposeParallelFlowable(ParallelFlowable<T> source, Maybe<?> scope) { | ||
this.source = source; | ||
this.scope = scope; | ||
} | ||
|
||
@Override public void subscribe(Subscriber<? super T>[] subscribers) { | ||
if (!validate(subscribers)) { | ||
return; | ||
} | ||
|
||
Subscriber<? super T>[] newSubscribers = new Subscriber[subscribers.length]; | ||
for (int i = 0; i < subscribers.length; i++) { | ||
AutoDisposingSubscriberImpl<? super T> subscriber = | ||
new AutoDisposingSubscriberImpl<>(scope, subscribers[i]); | ||
newSubscribers[i] = subscriber; | ||
} | ||
source.subscribe(newSubscribers); | ||
} | ||
|
||
@Override public int parallelism() { | ||
return source.parallelism(); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
autodispose/src/main/java/com/uber/autodispose/ParallelFlowableSubscribeProxy.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.uber.autodispose; | ||
|
||
import org.reactivestreams.Subscriber; | ||
|
||
import io.reactivex.annotations.NonNull; | ||
import io.reactivex.parallel.ParallelFlowable; | ||
|
||
/** | ||
* Subscribe proxy that matches {@link ParallelFlowable}'s subscribe overloads. | ||
*/ | ||
public interface ParallelFlowableSubscribeProxy<T> { | ||
|
||
/** | ||
* Proxy for {@link ParallelFlowable#subscribe(Subscriber[])}. | ||
*/ | ||
void subscribe(@NonNull Subscriber<? super T>[] subscribers); | ||
} |
Oops, something went wrong.