|
23 | 23 | import rx.internal.producers.SingleProducer;
|
24 | 24 | import rx.internal.schedulers.EventLoopsScheduler;
|
25 | 25 | import rx.observers.Subscribers;
|
26 |
| -import rx.schedulers.Schedulers; |
27 | 26 |
|
28 | 27 | /**
|
29 | 28 | * An Observable that emits a single constant scalar value to Subscribers.
|
|
34 | 33 | * @param <T> the value type
|
35 | 34 | */
|
36 | 35 | public final class ScalarSynchronousObservable<T> extends Observable<T> {
|
37 |
| - |
38 |
| - /** |
39 |
| - * We expect the Schedulers.computation() to return an EventLoopsScheduler all the time. |
40 |
| - */ |
41 |
| - static final Func1<Action0, Subscription> COMPUTATION_ONSCHEDULE = new Func1<Action0, Subscription>() { |
42 |
| - final EventLoopsScheduler els = (EventLoopsScheduler)Schedulers.computation(); |
43 |
| - |
44 |
| - @Override |
45 |
| - public Subscription call(Action0 t) { |
46 |
| - return els.scheduleDirect(t); |
47 |
| - } |
48 |
| - }; |
49 |
| - |
50 | 36 | /**
|
51 | 37 | * Indicates that the Producer used by this Observable should be fully
|
52 | 38 | * threadsafe. It is possible, but unlikely that multiple concurrent
|
@@ -115,7 +101,13 @@ public T get() {
|
115 | 101 | public Observable<T> scalarScheduleOn(final Scheduler scheduler) {
|
116 | 102 | final Func1<Action0, Subscription> onSchedule;
|
117 | 103 | if (scheduler instanceof EventLoopsScheduler) {
|
118 |
| - onSchedule = COMPUTATION_ONSCHEDULE; |
| 104 | + final EventLoopsScheduler els = (EventLoopsScheduler) scheduler; |
| 105 | + onSchedule = new Func1<Action0, Subscription>() { |
| 106 | + @Override |
| 107 | + public Subscription call(Action0 a) { |
| 108 | + return els.scheduleDirect(a); |
| 109 | + } |
| 110 | + }; |
119 | 111 | } else {
|
120 | 112 | onSchedule = new Func1<Action0, Subscription>() {
|
121 | 113 | @Override
|
|
0 commit comments