27
27
import java .util .concurrent .Future ;
28
28
import java .util .concurrent .TimeUnit ;
29
29
30
- import rx .Observable .OnSubscribe ;
31
30
import rx .joins .Pattern2 ;
32
31
import rx .joins .Plan0 ;
33
32
import rx .observables .BlockingObservable ;
34
33
import rx .observables .ConnectableObservable ;
35
34
import rx .observables .GroupedObservable ;
36
35
import rx .observers .SafeSubscriber ;
36
+ import rx .operators .OnSubscribeFromIterable ;
37
+ import rx .operators .OnSubscribeRange ;
37
38
import rx .operators .OperationAll ;
38
39
import rx .operators .OperationAmb ;
39
40
import rx .operators .OperationAny ;
50
51
import rx .operators .OperationDematerialize ;
51
52
import rx .operators .OperationDistinct ;
52
53
import rx .operators .OperationDistinctUntilChanged ;
53
- import rx .operators .Operator ;
54
- import rx .operators .OperatorDoOnEach ;
55
54
import rx .operators .OperationElementAt ;
56
55
import rx .operators .OperationFilter ;
57
56
import rx .operators .OperationFinally ;
65
64
import rx .operators .OperationMergeDelayError ;
66
65
import rx .operators .OperationMinMax ;
67
66
import rx .operators .OperationMulticast ;
68
- import rx .operators .OperationObserveOn ;
69
67
import rx .operators .OperationOnErrorResumeNextViaFunction ;
70
68
import rx .operators .OperationOnErrorResumeNextViaObservable ;
71
69
import rx .operators .OperationOnErrorReturn ;
72
70
import rx .operators .OperationOnExceptionResumeNextViaObservable ;
73
71
import rx .operators .OperationParallelMerge ;
74
- import rx .operators .OperatorRepeat ;
75
72
import rx .operators .OperationReplay ;
76
73
import rx .operators .OperationRetry ;
77
74
import rx .operators .OperationSample ;
98
95
import rx .operators .OperationToObservableFuture ;
99
96
import rx .operators .OperationUsing ;
100
97
import rx .operators .OperationWindow ;
101
- import rx .operators .OperatorSubscribeOn ;
102
- import rx .operators .OperatorZip ;
103
98
import rx .operators .Operator ;
104
99
import rx .operators .OperatorCast ;
105
- import rx .operators .OperatorFromIterable ;
100
+ import rx .operators .OperatorDoOnEach ;
106
101
import rx .operators .OperatorGroupBy ;
107
102
import rx .operators .OperatorMap ;
108
103
import rx .operators .OperatorMerge ;
104
+ import rx .operators .OperatorObserveOn ;
109
105
import rx .operators .OperatorParallel ;
106
+ import rx .operators .OperatorRepeat ;
107
+ import rx .operators .OperatorSubscribeOn ;
110
108
import rx .operators .OperatorTake ;
111
109
import rx .operators .OperatorTimestamp ;
112
110
import rx .operators .OperatorToObservableList ;
113
111
import rx .operators .OperatorToObservableSortedList ;
112
+ import rx .operators .OperatorZip ;
114
113
import rx .operators .OperatorZipIterable ;
115
114
import rx .plugins .RxJavaObservableExecutionHook ;
116
115
import rx .plugins .RxJavaPlugins ;
121
120
import rx .subjects .ReplaySubject ;
122
121
import rx .subjects .Subject ;
123
122
import rx .subscriptions .Subscriptions ;
123
+ import rx .util .Exceptions ;
124
124
import rx .util .OnErrorNotImplementedException ;
125
- import rx .util .Range ;
126
125
import rx .util .TimeInterval ;
127
126
import rx .util .Timestamped ;
128
127
import rx .util .functions .Action0 ;
@@ -1218,7 +1217,7 @@ public final static <T> Observable<T> from(Future<? extends T> future, Scheduler
1218
1217
* @see <a href="https://github.com/Netflix/RxJava/wiki/Creating-Observables#wiki-from">RxJava Wiki: from()</a>
1219
1218
*/
1220
1219
public final static <T > Observable <T > from (Iterable <? extends T > iterable ) {
1221
- return create (new OperatorFromIterable <T >(iterable ));
1220
+ return create (new OnSubscribeFromIterable <T >(iterable ));
1222
1221
}
1223
1222
1224
1223
/**
@@ -1240,7 +1239,7 @@ public final static <T> Observable<T> from(Iterable<? extends T> iterable) {
1240
1239
* @see <a href="http://msdn.microsoft.com/en-us/library/hh212140.aspx">MSDN: Observable.ToObservable</a>
1241
1240
*/
1242
1241
public final static <T > Observable <T > from (Iterable <? extends T > iterable , Scheduler scheduler ) {
1243
- return create (new OperatorFromIterable <T >(iterable )).subscribeOn (scheduler );
1242
+ return create (new OnSubscribeFromIterable <T >(iterable )).subscribeOn (scheduler );
1244
1243
}
1245
1244
1246
1245
/**
@@ -2440,7 +2439,13 @@ public final static <T> Observable<Observable<T>> parallelMerge(Observable<Obser
2440
2439
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229460.aspx">MSDN: Observable.Range</a>
2441
2440
*/
2442
2441
public final static Observable <Integer > range (int start , int count ) {
2443
- return from (Range .createWithCount (start , count ));
2442
+ if (count < 1 ) {
2443
+ throw new IllegalArgumentException ("Count must be positive" );
2444
+ }
2445
+ if ((start + count ) > Integer .MAX_VALUE ) {
2446
+ throw new IllegalArgumentException ("start + count can not exceed Integer.MAX_VALUE" );
2447
+ }
2448
+ return Observable .create (new OnSubscribeRange (start , start + (count - 1 )));
2444
2449
}
2445
2450
2446
2451
/**
@@ -2460,7 +2465,7 @@ public final static Observable<Integer> range(int start, int count) {
2460
2465
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211896.aspx">MSDN: Observable.Range</a>
2461
2466
*/
2462
2467
public final static Observable <Integer > range (int start , int count , Scheduler scheduler ) {
2463
- return from ( Range . createWithCount ( start , count ), scheduler );
2468
+ return range ( start , count ). subscribeOn ( scheduler );
2464
2469
}
2465
2470
2466
2471
/**
@@ -5140,8 +5145,7 @@ public final <R> ConnectableObservable<R> multicast(Subject<? super T, ? extends
5140
5145
}
5141
5146
5142
5147
/**
5143
- * Modify the source Observable so that it asynchronously notifies {@link Observer}s on the
5144
- * specified {@link Scheduler}.
5148
+ * Move notifications to the specified {@link Scheduler} one `onNext` at a time.
5145
5149
* <p>
5146
5150
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/observeOn.png">
5147
5151
*
@@ -5152,9 +5156,26 @@ public final <R> ConnectableObservable<R> multicast(Subject<? super T, ? extends
5152
5156
* @see <a href="https://github.com/Netflix/RxJava/wiki/Observable-Utility-Operators#wiki-observeon">RxJava Wiki: observeOn()</a>
5153
5157
*/
5154
5158
public final Observable <T > observeOn (Scheduler scheduler ) {
5155
- return create ( OperationObserveOn . observeOn ( this , scheduler ));
5159
+ return lift ( new OperatorObserveOn < T >( scheduler ));
5156
5160
}
5157
5161
5162
+ /**
5163
+ * Move notifications to the specified {@link Scheduler} asynchronously with a buffer of the given size.
5164
+ * <p>
5165
+ * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/observeOn.png">
5166
+ *
5167
+ * @param scheduler
5168
+ * the {@link Scheduler} to notify {@link Observer}s on
5169
+ * @param bufferSize
5170
+ * that will be rounded up to the next power of 2
5171
+ * @return the source Observable modified so that its {@link Observer}s are notified on the
5172
+ * specified {@link Scheduler}
5173
+ * @see <a href="https://github.com/Netflix/RxJava/wiki/Observable-Utility-Operators#wiki-observeon">RxJava Wiki: observeOn()</a>
5174
+ */
5175
+ public final Observable <T > observeOn (Scheduler scheduler , int bufferSize ) {
5176
+ return lift (new OperatorObserveOn <T >(scheduler , bufferSize ));
5177
+ }
5178
+
5158
5179
/**
5159
5180
* Filters the items emitted by an Observable, only emitting those of the specified type.
5160
5181
* <p>
@@ -5297,7 +5318,9 @@ public final Observable<T> onExceptionResumeNext(final Observable<? extends T> r
5297
5318
* @see <a href="https://github.com/Netflix/RxJava/wiki/Observable-Utility-Operators#wiki-parallel">RxJava Wiki: parallel()</a>
5298
5319
*/
5299
5320
public final <R > Observable <R > parallel (Func1 <Observable <T >, Observable <R >> f ) {
5300
- return lift (new OperatorParallel <T , R >(f , Schedulers .computation ()));
5321
+ // TODO move this back to Schedulers.computation() again once that is properly using eventloops
5322
+ // see https://github.com/Netflix/RxJava/issues/713 for why this was changed
5323
+ return lift (new OperatorParallel <T , R >(f , Schedulers .newThread ()));
5301
5324
}
5302
5325
5303
5326
/**
@@ -6966,10 +6989,9 @@ public void call() {
6966
6989
}
6967
6990
6968
6991
});
6969
- } catch (OnErrorNotImplementedException e ) {
6970
- // special handling when onError is not implemented ... we just rethrow
6971
- throw e ;
6972
6992
} catch (Throwable e ) {
6993
+ // special handling for certain Throwable/Error/Exception types
6994
+ Exceptions .throwIfFatal (e );
6973
6995
// if an unhandled error occurs executing the onSubscribe we will propagate it
6974
6996
try {
6975
6997
observer .onError (hook .onSubscribeError (this , e ));
0 commit comments