-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
1.x: Single.flatMapCompletable #4226
Changes from 1 commit
2513d60
6a01728
37ce576
7e33265
da742b4
6278eee
3338cec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1396,6 +1396,25 @@ public final <R> Observable<R> flatMapObservable(Func1<? super T, ? extends Obse | |
return Observable.merge(asObservable(map(func))); | ||
} | ||
|
||
public final Completable flatMapCompletable(final Func1<? super T, ? extends Completable> func) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please tag this as |
||
return Completable.create(new Completable.CompletableOnSubscribe() { | ||
@Override | ||
public void call(final Completable.CompletableSubscriber completableSubscriber) { | ||
subscribe(new SingleSubscriber<T>() { | ||
@Override | ||
public void onSuccess(final T value) { | ||
func.call(value).subscribe(completableSubscriber); | ||
} | ||
|
||
@Override | ||
public void onError(final Throwable error) { | ||
completableSubscriber.onError(error); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Returns a Single that applies a specified function to the item emitted by the source Single and | ||
* emits the result of this function application. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2005,4 +2005,32 @@ public Single<Integer> call(Integer v) { | |
assertFalse("Observers present?!", ps.hasObservers()); | ||
} | ||
|
||
@Test | ||
public void flatMapCompletableComplete() { | ||
TestSubscriber testSubscriber = new TestSubscriber(); | ||
|
||
Single.just(1).flatMapCompletable(new Func1<Integer, Completable>() { | ||
@Override | ||
public Completable call(final Integer integer) { | ||
return Completable.complete(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be better to test against more complicated |
||
} | ||
}).subscribe(testSubscriber); | ||
|
||
testSubscriber.assertCompleted(); | ||
} | ||
|
||
@Test | ||
public void flatMapCompletableError() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
final RuntimeException error = new RuntimeException("some error"); | ||
TestSubscriber testSubscriber = new TestSubscriber(); | ||
|
||
Single.just(1).flatMapCompletable(new Func1<Integer, Completable>() { | ||
@Override | ||
public Completable call(final Integer integer) { | ||
return Completable.error(error); | ||
} | ||
}).subscribe(testSubscriber); | ||
|
||
testSubscriber.assertError(error); | ||
} | ||
} |
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.
javadoc