|
16 | 16 | package rx.plugins;
|
17 | 17 |
|
18 | 18 | import java.lang.Thread.UncaughtExceptionHandler;
|
| 19 | +import java.util.concurrent.ScheduledExecutorService; |
19 | 20 |
|
20 | 21 | import rx.*;
|
21 | 22 | import rx.Completable.*;
|
@@ -67,6 +68,8 @@ public final class RxJavaHooks {
|
67 | 68 | static volatile Func1<Subscription, Subscription> onObservableReturn;
|
68 | 69 |
|
69 | 70 | static volatile Func1<Subscription, Subscription> onSingleReturn;
|
| 71 | + |
| 72 | + static volatile Func0<? extends ScheduledExecutorService> onGenericScheduledExecutorService; |
70 | 73 |
|
71 | 74 | static volatile Func1<Throwable, Throwable> onObservableSubscribeError;
|
72 | 75 |
|
@@ -230,6 +233,7 @@ public static void reset() {
|
230 | 233 | onComputationScheduler = null;
|
231 | 234 | onIOScheduler = null;
|
232 | 235 | onNewThreadScheduler = null;
|
| 236 | + onGenericScheduledExecutorService = null; |
233 | 237 | }
|
234 | 238 |
|
235 | 239 | /**
|
@@ -265,8 +269,9 @@ public static void clear() {
|
265 | 269 | onComputationScheduler = null;
|
266 | 270 | onIOScheduler = null;
|
267 | 271 | onNewThreadScheduler = null;
|
268 |
| - |
| 272 | + |
269 | 273 | onScheduleAction = null;
|
| 274 | + onGenericScheduledExecutorService = null; |
270 | 275 | }
|
271 | 276 |
|
272 | 277 | /**
|
@@ -1195,4 +1200,34 @@ public CompletableOnSubscribe call(CompletableOnSubscribe f) {
|
1195 | 1200 | };
|
1196 | 1201 |
|
1197 | 1202 | }
|
| 1203 | + /** |
| 1204 | + * Sets the hook function for returning a ScheduledExecutorService used |
| 1205 | + * by the GenericScheduledExecutorService for background tasks. |
| 1206 | + * <p> |
| 1207 | + * This operation is threadsafe. |
| 1208 | + * <p> |
| 1209 | + * Calling with a {@code null} parameter restores the default behavior: |
| 1210 | + * create the default with {@link java.util.concurrent.Executors#newScheduledThreadPool(int, java.util.concurrent.ThreadFactory)}. |
| 1211 | + * <p> |
| 1212 | + * For the changes to take effect, the Schedulers has to be restarted. |
| 1213 | + * @param factory the supplier that is called when the GenericScheduledExecutorService |
| 1214 | + * is (re)started |
| 1215 | + */ |
| 1216 | + public static void setOnGenericScheduledExecutorService(Func0<? extends ScheduledExecutorService> factory) { |
| 1217 | + if (lockdown) { |
| 1218 | + return; |
| 1219 | + } |
| 1220 | + onGenericScheduledExecutorService = factory; |
| 1221 | + } |
| 1222 | + |
| 1223 | + /** |
| 1224 | + * Returns the current factory for creating ScheduledExecutorServices in |
| 1225 | + * GenericScheduledExecutorService utility. |
| 1226 | + * <p> |
| 1227 | + * This operation is threadsafe. |
| 1228 | + * @return the current factory function |
| 1229 | + */ |
| 1230 | + public static Func0<? extends ScheduledExecutorService> getOnGenericScheduledExecutorService() { |
| 1231 | + return onGenericScheduledExecutorService; |
| 1232 | + } |
1198 | 1233 | }
|
0 commit comments