Scheduler. The only parameter is a
function that flattens an Observable of Observable of
Completables into just one Completable. There must be a chain
of operators connecting the returned value to the source Observable
otherwise any work scheduled on the returned Scheduler will not be
executed.
When Scheduler#createWorker() is invoked a Observable of
Completables is onNext'd to the combinator to be flattened. If the
inner Observable is not immediately subscribed to an calls to
Worker#schedule are buffered. Once the Observable is
subscribed to actions are then onNext'd as Completables.
Finally the actions scheduled on the parent Scheduler when the inner
most Completables are subscribed to.
When the Worker is unsubscribed the Completable emits an
onComplete and triggers any behavior in the flattening operator. The
Observable and all Completables give to the flattening
function never onError.
Limit the amount concurrency two at a time without creating a new fix size thread pool:
Scheduler limitScheduler = Schedulers.computation().when(workers -> {
// use merge max concurrent to limit the number of concurrent
// callbacks two at a time
return Completable.merge(Observable.merge(workers), 2);
});
This is a slightly different way to limit the concurrency but it has some
interesting benefits and drawbacks to the method above. It works by limited
the number of concurrent Workers rather than individual actions.
Generally each Observable uses its own Worker. This means
that this will essentially limit the number of concurrent subscribes. The
danger comes from using operators like
Flowable#zip(org. where
subscribing to the first Observable could deadlock the subscription
to the second.
Scheduler limitScheduler = Schedulers.computation().when(workers -> {
// use merge max concurrent to limit the number of concurrent
// Observables two at a time
return Completable.merge(Observable.merge(workers, 2));
});
Slowing down the rate to no more than than 1 a second. This suffers from the
same problem as the one above I could find an Observable operator
that limits the rate without dropping the values (aka leaky bucket
algorithm).
Scheduler slowScheduler = Schedulers.computation().when(workers -> {
// use concatenate to make each worker happen one at a time.
return Completable.concat(workers.map(actions -> {
// delay the starting of the next worker by 1 second.
return Completable.merge(actions.delaySubscription(1, TimeUnit.SECONDS));
}));
});
History 2.0.1 - experimental
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv abstract static class | |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| private final Scheduler | |
| private Disposable | |
| pack-priv static final Disposable | |
| pack-priv static final Disposable | |
| private final FlowableProcessor |
| Access | Constructor and Description |
|---|---|
| public | SchedulerWhen(Function<Flowable<Flowable<Completable>>, Completable> combine, Scheduler actualScheduler)
|
| Modifier and Type | Method and Description |
|---|---|
| public Scheduler. | createWorker()
Implements abstract io. Scheduler. that represents sequential execution of actions.
|
| public void | dispose()
Implements io. |
| public boolean | isDisposed()
Implements io. |
| actualScheduler | back to summary |
|---|---|
| private final Scheduler actualScheduler | |
| disposable | back to summary |
|---|---|
| private Disposable disposable | |
| DISPOSED | back to summary |
|---|---|
| pack-priv static final Disposable DISPOSED | |
| SUBSCRIBED | back to summary |
|---|---|
| pack-priv static final Disposable SUBSCRIBED | |
| workerProcessor | back to summary |
|---|---|
| private final FlowableProcessor<Flowable<Completable>> workerProcessor | |
| SchedulerWhen | back to summary |
|---|---|
| public SchedulerWhen(Function<Flowable<Flowable<Completable>>, Completable> combine, Scheduler actualScheduler) | |
| createWorker | back to summary |
|---|---|
| public Scheduler. Implements abstract io. Doc from io. Retrieves or creates a new
When work is completed, the
Work on a | |
| dispose | back to summary |
|---|---|
| public void dispose() Implements io. Doc from io. Dispose the resource, the operation should be idempotent.
| |
| isDisposed | back to summary |
|---|---|
| public boolean isDisposed() Implements io. Doc from io. Returns true if this resource has been disposed.
| |
| Modifier and Type | Class and Description |
|---|---|
| pack-priv class |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public Completable | apply(final SchedulerWhen.
the input value actionImplements io. |
| actualWorker | back to summary |
|---|---|
| pack-priv final Scheduler. | |
| CreateWorkerFunction | back to summary |
|---|---|
| pack-priv CreateWorkerFunction(Scheduler. | |
| apply | back to summary |
|---|---|
| public Completable apply(final SchedulerWhen. Implements io. Doc from io. Apply some calculation to the input value and return some other value.
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final SchedulerWhen. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| protected void | subscribeActual(CompletableObserver
the CompletableObserver instance, never null actionCompletable)Implements abstract io. CompletableObservers and
perform the business logic in your operator.
|
| action | back to summary |
|---|---|
| pack-priv final SchedulerWhen. | |
| WorkerCompletable | back to summary |
|---|---|
| pack-priv WorkerCompletable(SchedulerWhen. | |
| subscribeActual | back to summary |
|---|---|
| protected void subscribeActual(CompletableObserver actionCompletable) Implements abstract io. Doc from io. Implement this method to handle the incoming There is no need to call any of the plugin hooks on the current
| |
| Modifier and Type | Field and Description |
|---|---|
| private final Runnable | |
| private final long | |
| private final TimeUnit |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| protected Disposable | callActual(Scheduler.
Implements abstract io. |
| action | back to summary |
|---|---|
| private final Runnable action | |
| delayTime | back to summary |
|---|---|
| private final long delayTime | |
| unit | back to summary |
|---|---|
| private final TimeUnit unit | |
| DelayedAction | back to summary |
|---|---|
| pack-priv DelayedAction(Runnable action, long delayTime, TimeUnit unit) | |
| callActual | back to summary |
|---|---|
| protected Disposable callActual(Scheduler. Implements abstract io.
| |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| protected Disposable | callActual(Scheduler.
Implements abstract io. |
| action | back to summary |
|---|---|
| private final Runnable action | |
| ImmediateAction | back to summary |
|---|---|
| pack-priv ImmediateAction(Runnable action) | |
| callActual | back to summary |
|---|---|
| protected Disposable callActual(Scheduler. Implements abstract io.
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final Runnable | |
| pack-priv final CompletableObserver |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| action | back to summary |
|---|---|
| pack-priv final Runnable action | |
| actionCompletable | back to summary |
|---|---|
| pack-priv final CompletableObserver actionCompletable | |
| OnCompletedAction | back to summary |
|---|---|
| pack-priv OnCompletedAction(Runnable action, CompletableObserver actionCompletable) | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final FlowableProcessor | |
| private final Scheduler. | |
| private final AtomicBoolean |
| Access | Constructor and Description |
|---|---|
| pack-priv | QueueWorker(FlowableProcessor<SchedulerWhen.
|
| Modifier and Type | Method and Description |
|---|---|
| public void | dispose()
Implements io. |
| public boolean | isDisposed()
Implements io. |
| public Disposable | schedule(final Runnable
the Runnable to schedule action, final long time to "wait" before executing the action; non-positive values indicate an non-delayed
schedule delayTime, final TimeUnit the time unit of unit)delayTimeImplements abstract io. |
| public Disposable | schedule(final Runnable
Runnable to schedule action)Overrides io. |
| actionProcessor | back to summary |
|---|---|
| private final FlowableProcessor<SchedulerWhen. | |
| actualWorker | back to summary |
|---|---|
| private final Scheduler. | |
| unsubscribed | back to summary |
|---|---|
| private final AtomicBoolean unsubscribed | |
| QueueWorker | back to summary |
|---|---|
| pack-priv QueueWorker(FlowableProcessor<SchedulerWhen. | |
| dispose | back to summary |
|---|---|
| public void dispose() Implements io. Doc from io. Dispose the resource, the operation should be idempotent.
| |
| isDisposed | back to summary |
|---|---|
| public boolean isDisposed() Implements io. Doc from io. Returns true if this resource has been disposed.
| |
| schedule | back to summary |
|---|---|
| public Disposable schedule(final Runnable action, final long delayTime, final TimeUnit unit) Implements abstract io. Doc from io. Schedules an Runnable for execution at some point in the future specified by a time delay relative to the current time.
Note to implementors: non-positive
| |
| schedule | back to summary |
|---|---|
| public Disposable schedule(final Runnable action) Overrides io. Doc from io. Schedules a Runnable for execution without any time delay. The default implementation delegates to
| |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| protected abstract Disposable | |
| public void | dispose()
Implements io. |
| public boolean | isDisposed()
Implements io. |
| ScheduledAction | back to summary |
|---|---|
| pack-priv ScheduledAction() | |
| call | back to summary |
|---|---|
| pack-priv void call(Scheduler. | |
| callActual | back to summary |
|---|---|
| protected abstract Disposable callActual(Scheduler. | |
| dispose | back to summary |
|---|---|
| public void dispose() Implements io. Doc from io. Dispose the resource, the operation should be idempotent.
| |
| isDisposed | back to summary |
|---|---|
| public boolean isDisposed() Implements io. Doc from io. Returns true if this resource has been disposed.
| |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | dispose()
Implements io. |
| public boolean | isDisposed()
Implements io. |
| SubscribedDisposable | back to summary |
|---|---|
| pack-priv SubscribedDisposable() | |
| dispose | back to summary |
|---|---|
| public void dispose() Implements io. Doc from io. Dispose the resource, the operation should be idempotent.
| |
| isDisposed | back to summary |
|---|---|
| public boolean isDisposed() Implements io. Doc from io. Returns true if this resource has been disposed.
| |