Skip to content

Commit c2084cb

Browse files
Merge pull request ReactiveX#664 from akarnokd/OperationAsObservable
Operation AsObservable
2 parents 0df652c + d914b7c commit c2084cb

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

rxjava-core/src/main/java/rx/Observable.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import rx.operators.OperationAll;
3636
import rx.operators.OperationAmb;
3737
import rx.operators.OperationAny;
38+
import rx.operators.OperationAsObservable;
3839
import rx.operators.OperationAverage;
3940
import rx.operators.OperationBuffer;
4041
import rx.operators.OperationCache;
@@ -511,6 +512,14 @@ public Subscription subscribe(final Action1<? super T> onNext, final Action1<Thr
511512
return subscribeOn(scheduler).subscribe(onNext, onError, onComplete);
512513
}
513514

515+
/**
516+
* Hides the identity of this observable.
517+
* @return an Observable hiding the identity of this Observable.
518+
*/
519+
public Observable<T> asObservable() {
520+
return create(new OperationAsObservable<T>(this));
521+
}
522+
514523
/**
515524
* Returns a {@link ConnectableObservable} that upon connection causes the
516525
* source Observable to push results into the specified subject.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package rx.operators;
17+
18+
import rx.Observable;
19+
import rx.Observable.OnSubscribeFunc;
20+
import rx.Observer;
21+
import rx.Subscription;
22+
23+
/**
24+
* Hides the identity of another observable.
25+
* @param <T> the return value type of the wrapped observable.
26+
*/
27+
public final class OperationAsObservable<T> implements OnSubscribeFunc<T> {
28+
private final Observable<? extends T> source;
29+
30+
public OperationAsObservable(Observable<? extends T> source) {
31+
this.source = source;
32+
}
33+
@Override
34+
public Subscription onSubscribe(Observer<? super T> t1) {
35+
return source.subscribe(t1);
36+
}
37+
}

0 commit comments

Comments
 (0)