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 rx. 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 rx.s rather than individual actions.
Generally each Observable uses its own rx.. This means
that this will essentially limit the number of concurrent subscribes. The
danger comes from using operators like
Observable#zip(Observable, Observable, rx. 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));
}));
});
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv abstract static class |
| Modifier and Type | Field and Description |
|---|---|
| private final Scheduler | |
| pack-priv static final Subscription | |
| private final Subscription | |
| pack-priv static final Subscription | |
| private final Observer |
| Access | Constructor and Description |
|---|---|
| public | SchedulerWhen(Func1<Observable<Observable<Completable>>, Completable> combine, Scheduler actualScheduler)
|
| Modifier and Type | Method and Description |
|---|---|
| public Scheduler. | createWorker()
Implements abstract rx. Scheduler. that represents serial execution of actions.
|
| public boolean | isUnsubscribed()
Implements rx. Subscription is currently unsubscribed.
|
| public void | unsubscribe()
Implements rx. Subscriber that was registered when this Subscription
was received.
|
| actualScheduler | back to summary |
|---|---|
| private final Scheduler actualScheduler | |
| SUBSCRIBED | back to summary |
|---|---|
| pack-priv static final Subscription SUBSCRIBED | |
| subscription | back to summary |
|---|---|
| private final Subscription subscription | |
| UNSUBSCRIBED | back to summary |
|---|---|
| pack-priv static final Subscription UNSUBSCRIBED | |
| workerObserver | back to summary |
|---|---|
| private final Observer<Observable<Completable>> workerObserver | |
| SchedulerWhen | back to summary |
|---|---|
| public SchedulerWhen(Func1<Observable<Observable<Completable>>, Completable> combine, Scheduler actualScheduler) | |
| createWorker | back to summary |
|---|---|
| public Scheduler. Implements abstract rx. Doc from rx. Retrieves or creates a new
When work is completed it should be unsubscribed using
Work on a | |
| isUnsubscribed | back to summary |
|---|---|
| public boolean isUnsubscribed() Implements rx. Doc from rx. Indicates whether this
| |
| unsubscribe | back to summary |
|---|---|
| public void unsubscribe() Implements rx. Doc from rx. Stops the receipt of notifications on the
This allows deregistering an
| |
| Modifier and Type | Field and Description |
|---|---|
| private final Action0 | |
| private final long | |
| private final TimeUnit |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected Subscription | callActual(Scheduler.
Implements abstract rx. |
| action | back to summary |
|---|---|
| private final Action0 action | |
| delayTime | back to summary |
|---|---|
| private final long delayTime | |
| unit | back to summary |
|---|---|
| private final TimeUnit unit | |
| DelayedAction | back to summary |
|---|---|
| public DelayedAction(Action0 action, long delayTime, TimeUnit unit) | |
| callActual | back to summary |
|---|---|
| protected Subscription callActual(Scheduler. Implements abstract rx.
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected Subscription | callActual(Scheduler.
Implements abstract rx. |
| action | back to summary |
|---|---|
| private final Action0 action | |
| ImmediateAction | back to summary |
|---|---|
| public ImmediateAction(Action0 action) | |
| callActual | back to summary |
|---|---|
| protected Subscription callActual(Scheduler. Implements abstract rx.
| |
| Modifier and Type | Field and Description |
|---|---|
| private Action0 | |
| private CompletableSubscriber |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| action | back to summary |
|---|---|
| private Action0 action | |
| actionCompletable | back to summary |
|---|---|
| private CompletableSubscriber actionCompletable | |
| OnCompletedAction | back to summary |
|---|---|
| public OnCompletedAction(Action0 action, CompletableSubscriber actionCompletable) | |
| call | back to summary |
|---|---|
| public void call() Implements rx.
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| protected abstract Subscription | |
| public boolean | isUnsubscribed()
Implements rx. Subscription is currently unsubscribed.
|
| public void | unsubscribe()
Implements rx. Subscriber that was registered when this Subscription
was received.
|
| ScheduledAction | back to summary |
|---|---|
| public ScheduledAction() | |
| call | back to summary |
|---|---|
| private void call(Scheduler. | |
| callActual | back to summary |
|---|---|
| protected abstract Subscription callActual(Scheduler. | |
| isUnsubscribed | back to summary |
|---|---|
| public boolean isUnsubscribed() Implements rx. Doc from rx. Indicates whether this
| |
| unsubscribe | back to summary |
|---|---|
| public void unsubscribe() Implements rx. Doc from rx. Stops the receipt of notifications on the
This allows deregistering an
| |