2222
2323import rx .Observable ;
2424import rx .Subscriber ;
25- import rx .Subscription ;
2625import rx .functions .Action1 ;
2726import rx .functions .Func1 ;
28- import rx .observers .SafeSubscriber ;
29- import rx .operators .OperationLatest ;
30- import rx .operators .OperationMostRecent ;
31- import rx .operators .OperationNext ;
32- import rx .operators .OperationToFuture ;
33- import rx .operators .OperationToIterator ;
27+ import rx .operators .BlockingOperatorLatest ;
28+ import rx .operators .BlockingOperatorMostRecent ;
29+ import rx .operators .BlockingOperatorNext ;
30+ import rx .operators .BlockingOperatorToFuture ;
31+ import rx .operators .BlockingOperatorToIterator ;
3432
3533/**
3634 * An extension of {@link Observable} that provides blocking operators.
@@ -64,17 +62,6 @@ public static <T> BlockingObservable<T> from(final Observable<? extends T> o) {
6462 return new BlockingObservable <T >(o );
6563 }
6664
67- /**
68- * Used for protecting against errors being thrown from {@link Subscriber} implementations and ensuring onNext/onError/onCompleted contract
69- * compliance.
70- * <p>
71- * See https://github.com/Netflix/RxJava/issues/216 for discussion on
72- * "Guideline 6.4: Protect calls to user code from within an operator"
73- */
74- private Subscription protectivelyWrapAndSubscribe (Subscriber <? super T > observer ) {
75- return o .subscribe (new SafeSubscriber <T >(observer ));
76- }
77-
7865 /**
7966 * Invoke a method on each item emitted by the {@link Observable}; block
8067 * until the Observable completes.
@@ -97,12 +84,10 @@ public void forEach(final Action1<? super T> onNext) {
9784 final AtomicReference <Throwable > exceptionFromOnError = new AtomicReference <Throwable >();
9885
9986 /**
100- * Wrapping since raw functions provided by the user are being invoked.
101- *
102- * See https://github.com/Netflix/RxJava/issues/216 for discussion on
103- * "Guideline 6.4: Protect calls to user code from within an operator"
87+ * Use 'subscribe' instead of 'unsafeSubscribe' for Rx contract behavior
88+ * as this is the final subscribe in the chain.
10489 */
105- protectivelyWrapAndSubscribe (new Subscriber <T >() {
90+ o . subscribe (new Subscriber <T >() {
10691 @ Override
10792 public void onCompleted () {
10893 latch .countDown ();
@@ -158,7 +143,7 @@ public void onNext(T args) {
158143 * @see <a href="https://github.com/Netflix/RxJava/wiki/Blocking-Observable-Operators#transformations-tofuture-toiterable-and-toiteratorgetiterator">RxJava Wiki: getIterator()</a>
159144 */
160145 public Iterator <T > getIterator () {
161- return OperationToIterator .toIterator (o );
146+ return BlockingOperatorToIterator .toIterator (o );
162147 }
163148
164149 /**
@@ -311,7 +296,7 @@ public T lastOrDefault(T defaultValue, Func1<? super T, Boolean> predicate) {
311296 * @see <a href="http://msdn.microsoft.com/en-us/library/hh229751.aspx">MSDN: Observable.MostRecent</a>
312297 */
313298 public Iterable <T > mostRecent (T initialValue ) {
314- return OperationMostRecent .mostRecent (o , initialValue );
299+ return BlockingOperatorMostRecent .mostRecent (o , initialValue );
315300 }
316301
317302 /**
@@ -324,7 +309,7 @@ public Iterable<T> mostRecent(T initialValue) {
324309 * @see <a href="http://msdn.microsoft.com/en-us/library/hh211897.aspx">MSDN: Observable.Next</a>
325310 */
326311 public Iterable <T > next () {
327- return OperationNext .next (o );
312+ return BlockingOperatorNext .next (o );
328313 }
329314
330315 /**
@@ -344,7 +329,7 @@ public Iterable<T> next() {
344329 * @see <a href="http://msdn.microsoft.com/en-us/library/hh212115.aspx">MSDN: Observable.Latest</a>
345330 */
346331 public Iterable <T > latest () {
347- return OperationLatest .latest (o );
332+ return BlockingOperatorLatest .latest (o );
348333 }
349334
350335 /**
@@ -441,7 +426,7 @@ public T singleOrDefault(T defaultValue, Func1<? super T, Boolean> predicate) {
441426 * @see <a href="https://github.com/Netflix/RxJava/wiki/Blocking-Observable-Operators#transformations-tofuture-toiterable-and-toiteratorgetiterator">RxJava Wiki: toFuture()</a>
442427 */
443428 public Future <T > toFuture () {
444- return OperationToFuture .toFuture (o );
429+ return BlockingOperatorToFuture .toFuture (o );
445430 }
446431
447432 /**
0 commit comments