-
Notifications
You must be signed in to change notification settings - Fork 226
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
Parallel flowable support #155
Merged
ZacSweers
merged 9 commits into
uber:master
from
VisheshVadhera:parallel-flowable-support
Jan 7, 2018
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fa77790
Add support for parallelFlowable
VisheshVadhera bdaaa89
Merge branch 'master' of github.com:uber/AutoDispose into parallel-fl…
VisheshVadhera f922553
Change Readme to mention support for parallelFlowable as well
VisheshVadhera 4b3e414
Add Kotlin tests
VisheshVadhera 6815058
Fix docs for parallelFlowable
VisheshVadhera 3b79764
Fix checkStyle errors
VisheshVadhera 3ece703
Fix nitpicks
VisheshVadhera 0df33c1
Validate subscribers and replace to() with as()
VisheshVadhera 7e22cbc
Rename ParallelFlowableConverter to ParallelFlowableScoper
VisheshVadhera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of wonder if we do need a separate subscriber that manages all the subscribers here. @akarnokd penny for your thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parallel rails are largely independent and act as their own Flowables. That's why many parallel operators just delegate to their sequential versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, in that case we can leave this as-is 👍