Skip to content

Commit 6870e7e

Browse files
Single.toObservable
1 parent 1e2a725 commit 6870e7e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/main/java/rx/Single.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,17 @@ public void onNext(T t) {
16491649
public final Single<T> subscribeOn(Scheduler scheduler) {
16501650
return nest().lift(new OperatorSubscribeOn<T>(scheduler));
16511651
}
1652+
1653+
/**
1654+
* Converts this Single into an {@link Observable}.
1655+
* <p>
1656+
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.toObservable.png" alt="">
1657+
*
1658+
* @return an {@link Observable} that emits a single item T.
1659+
*/
1660+
public final Observable<T> toObservable() {
1661+
return asObservable(this);
1662+
}
16521663

16531664
/**
16541665
* Returns a Single that mirrors the source Single but applies a timeout policy for its emitted item. If it

src/test/java/rx/SingleTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,4 +452,13 @@ public void onStart() {
452452

453453
ts.assertValue("hello");
454454
}
455+
456+
@Test
457+
public void testToObservable() {
458+
Observable<String> a = Single.just("a").toObservable();
459+
TestSubscriber<String> ts = TestSubscriber.create();
460+
a.subscribe(ts);
461+
ts.assertValue("a");
462+
ts.assertCompleted();
463+
}
455464
}

0 commit comments

Comments
 (0)