|
| 1 | +package rx.lang.scala.concurrency |
| 2 | + |
| 3 | +import rx.Scheduler |
| 4 | +import java.util.concurrent.Executor |
| 5 | +import java.util.concurrent.ScheduledExecutorService |
| 6 | + |
| 7 | +/** |
| 8 | + * Factory methods for creating Schedulers. |
| 9 | + */ |
| 10 | +object Schedulers { |
| 11 | + |
| 12 | + /** |
| 13 | + * Returns a [[rx.lang.scala.Scheduler]] that executes work immediately on the current thread. |
| 14 | + */ |
| 15 | + def immediate: Scheduler = rx.concurrency.Schedulers.immediate() |
| 16 | + |
| 17 | + /** |
| 18 | + * Returns a [[rx.lang.scala.Scheduler]] that queues work on the current thread to be executed after the current work completes. |
| 19 | + */ |
| 20 | + def currentThread: Scheduler = rx.concurrency.Schedulers.currentThread() |
| 21 | + |
| 22 | + /** |
| 23 | + * Returns a [[rx.lang.scala.Scheduler]] that creates a new {@link Thread} for each unit of work. |
| 24 | + */ |
| 25 | + def newThread: Scheduler = rx.concurrency.Schedulers.newThread |
| 26 | + |
| 27 | + /** |
| 28 | + * Returns a [[rx.lang.scala.Scheduler]] that queues work on an [[java.util.concurrent.Executor]]. |
| 29 | + * |
| 30 | + * Note that this does not support scheduled actions with a delay. |
| 31 | + */ |
| 32 | + def executor(executor: Executor): Scheduler = rx.concurrency.Schedulers.executor(executor) |
| 33 | + |
| 34 | + /** |
| 35 | + * Returns a [[rx.lang.scala.Scheduler]] that queues work on an [[java.util.concurrent.ScheduledExecutorService]]. |
| 36 | + */ |
| 37 | + def executor(executor: ScheduledExecutorService): Scheduler = rx.concurrency.Schedulers.executor(executor) |
| 38 | + |
| 39 | + /** |
| 40 | + * Returns a [[rx.lang.scala.Scheduler]] intended for computational work. |
| 41 | + * |
| 42 | + * The implementation is backed by a [[java.util.concurrent.ScheduledExecutorService]] thread-pool sized to the number of CPU cores. |
| 43 | + * |
| 44 | + * This can be used for event-loops, processing callbacks and other computational work. |
| 45 | + * |
| 46 | + * Do not perform IO-bound work on this scheduler. Use [[rx.lang.scala.concurrency.Schedulers.threadPoolForIO]] instead. |
| 47 | + */ |
| 48 | + def threadPoolForComputation: Scheduler = rx.concurrency.Schedulers.threadPoolForComputation() |
| 49 | + |
| 50 | + /** |
| 51 | + * [[rx.lang.scala.Scheduler]] intended for IO-bound work. |
| 52 | + * |
| 53 | + * The implementation is backed by an [[java.util.concurrent.Executor]] thread-pool that will grow as needed. |
| 54 | + * |
| 55 | + * This can be used for asynchronously performing blocking IO. |
| 56 | + * |
| 57 | + * Do not perform computational work on this scheduler. Use [[rx.lang.scala.concurrency.Schedulers.threadPoolForComputation]] instead. |
| 58 | + */ |
| 59 | + def threadPoolForIO: Scheduler = rx.concurrency.Schedulers.threadPoolForIO() |
| 60 | + |
| 61 | +} |
0 commit comments