|
12 | 12 | */
|
13 | 13 | package io.reactivex.plugins;
|
14 | 14 |
|
15 |
| -import java.lang.Thread.UncaughtExceptionHandler; |
16 |
| -import java.util.concurrent.Callable; |
17 |
| - |
18 |
| -import io.reactivex.internal.functions.ObjectHelper; |
19 |
| -import org.reactivestreams.Subscriber; |
20 |
| - |
21 | 15 | import io.reactivex.*;
|
| 16 | +import io.reactivex.annotations.Experimental; |
22 | 17 | import io.reactivex.flowables.ConnectableFlowable;
|
23 | 18 | import io.reactivex.functions.*;
|
| 19 | +import io.reactivex.internal.functions.ObjectHelper; |
| 20 | +import io.reactivex.internal.schedulers.*; |
24 | 21 | import io.reactivex.internal.util.ExceptionHelper;
|
25 | 22 | import io.reactivex.observables.ConnectableObservable;
|
| 23 | +import io.reactivex.schedulers.Schedulers; |
| 24 | +import org.reactivestreams.Subscriber; |
| 25 | + |
| 26 | +import java.lang.Thread.UncaughtExceptionHandler; |
| 27 | +import java.util.concurrent.*; |
26 | 28 |
|
27 | 29 | /**
|
28 | 30 | * Utility class to inject handlers to certain standard RxJava operations.
|
@@ -926,6 +928,98 @@ public static Completable onAssembly(Completable source) {
|
926 | 928 | return source;
|
927 | 929 | }
|
928 | 930 |
|
| 931 | + /** |
| 932 | + * Create an instance of the default {@link Scheduler} used for {@link Schedulers#computation()}. |
| 933 | + * @return the created Scheduler instance |
| 934 | + * @since 2.0.5 - experimental |
| 935 | + */ |
| 936 | + @Experimental |
| 937 | + public static Scheduler newComputation() { |
| 938 | + return new ComputationScheduler(); |
| 939 | + } |
| 940 | + |
| 941 | + /** |
| 942 | + * Create an instance of the default {@link Scheduler} used for {@link Schedulers#computation()} |
| 943 | + * except using {@code threadFactory} for thread creation. |
| 944 | + * @param threadFactory thread factory to use for creating worker threads. Note that this takes precedence over any |
| 945 | + * system properties for configuring new thread creation. Cannot be null. |
| 946 | + * @return the created Scheduler instance |
| 947 | + * @since 2.0.5 - experimental |
| 948 | + */ |
| 949 | + @Experimental |
| 950 | + public static Scheduler newComputation(ThreadFactory threadFactory) { |
| 951 | + return new ComputationScheduler(ObjectHelper.requireNonNull(threadFactory, "threadFactory is null")); |
| 952 | + } |
| 953 | + |
| 954 | + /** |
| 955 | + * Create an instance of the default {@link Scheduler} used for {@link Schedulers#io()}. |
| 956 | + * @return the created Scheduler instance |
| 957 | + * @since 2.0.5 - experimental |
| 958 | + */ |
| 959 | + @Experimental |
| 960 | + public static Scheduler newIo() { |
| 961 | + return new IoScheduler(); |
| 962 | + } |
| 963 | + |
| 964 | + /** |
| 965 | + * Create an instance of the default {@link Scheduler} used for {@link Schedulers#io()} |
| 966 | + * except using {@code threadFactory} for thread creation. |
| 967 | + * @param threadFactory thread factory to use for creating worker threads. Note that this takes precedence over any |
| 968 | + * system properties for configuring new thread creation. Cannot be null. |
| 969 | + * @return the created Scheduler instance |
| 970 | + * @since 2.0.5 - experimental |
| 971 | + */ |
| 972 | + @Experimental |
| 973 | + public static Scheduler newIo(ThreadFactory threadFactory) { |
| 974 | + return new IoScheduler(ObjectHelper.requireNonNull(threadFactory, "threadFactory is null")); |
| 975 | + } |
| 976 | + |
| 977 | + /** |
| 978 | + * Create an instance of the default {@link Scheduler} used for {@link Schedulers#newThread()}. |
| 979 | + * @return the created Scheduler instance |
| 980 | + * @since 2.0.5 - experimental |
| 981 | + */ |
| 982 | + @Experimental |
| 983 | + public static Scheduler newNewThread() { |
| 984 | + return new NewThreadScheduler(); |
| 985 | + } |
| 986 | + |
| 987 | + /** |
| 988 | + * Create an instance of the default {@link Scheduler} used for {@link Schedulers#newThread()} |
| 989 | + * except using {@code threadFactory} for thread creation. |
| 990 | + * @param threadFactory thread factory to use for creating worker threads. Note that this takes precedence over any |
| 991 | + * system properties for configuring new thread creation. Cannot be null. |
| 992 | + * @return the created Scheduler instance |
| 993 | + * @since 2.0.5 - experimental |
| 994 | + */ |
| 995 | + @Experimental |
| 996 | + public static Scheduler newNewThread(ThreadFactory threadFactory) { |
| 997 | + return new NewThreadScheduler(ObjectHelper.requireNonNull(threadFactory, "threadFactory is null")); |
| 998 | + } |
| 999 | + |
| 1000 | + /** |
| 1001 | + * Create an instance of the default {@link Scheduler} used for {@link Schedulers#single()}. |
| 1002 | + * @return the created Scheduler instance |
| 1003 | + * @since 2.0.5 - experimental |
| 1004 | + */ |
| 1005 | + @Experimental |
| 1006 | + public static Scheduler newSingle() { |
| 1007 | + return new SingleScheduler(); |
| 1008 | + } |
| 1009 | + |
| 1010 | + /** |
| 1011 | + * Create an instance of the default {@link Scheduler} used for {@link Schedulers#single()} |
| 1012 | + * except using {@code threadFactory} for thread creation. |
| 1013 | + * @param threadFactory thread factory to use for creating worker threads. Note that this takes precedence over any |
| 1014 | + * system properties for configuring new thread creation. Cannot be null. |
| 1015 | + * @return the created Scheduler instance |
| 1016 | + * @since 2.0.5 - experimental |
| 1017 | + */ |
| 1018 | + @Experimental |
| 1019 | + public static Scheduler newSingle(ThreadFactory threadFactory) { |
| 1020 | + return new SingleScheduler(ObjectHelper.requireNonNull(threadFactory, "threadFactory is null")); |
| 1021 | + } |
| 1022 | + |
929 | 1023 | /**
|
930 | 1024 | * Wraps the call to the function in try-catch and propagates thrown
|
931 | 1025 | * checked exceptions as RuntimeException.
|
|
0 commit comments