Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delaySubscription() methods to Completable #5081 #6242

Merged
merged 4 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/main/java/io/reactivex/Completable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,51 @@ public final Completable delay(final long delay, final TimeUnit unit, final Sche
return RxJavaPlugins.onAssembly(new CompletableDelay(this, delay, unit, scheduler, delayError));
}

/**
* Returns a Completable that delays the subscription to the source CompletableSource by a given amount of time.
* <p>
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>This version of {@code delaySubscription} operates by default on the {@code computation} {@link Scheduler}.</dd>
* </dl>
*
* @param delay the time to delay the subscription
* @param unit the time unit of {@code delay}
* @return a Completable that delays the subscription to the source CompletableSource by the given amount
* @since 2.2.3 - experimental
* @see <a href="http://reactivex.io/documentation/operators/delay.html">ReactiveX operators documentation: Delay</a>
*/
@CheckReturnValue
@Experimental
@SchedulerSupport(SchedulerSupport.COMPUTATION)
public final Completable delaySubscription(long delay, TimeUnit unit) {
return delaySubscription(delay, unit, Schedulers.computation());
}

/**
* Returns a Completable that delays the subscription to the source CompletableSource by a given amount of time,
* both waiting and subscribing on a given Scheduler.
* <p>
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>You specify which {@link Scheduler} this operator will use.</dd>
* </dl>
*
* @param delay the time to delay the subscription
* @param unit the time unit of {@code delay}
* @param scheduler the Scheduler on which the waiting and subscription will happen
* @return a Completable that delays the subscription to the source CompletableSource by a given
* amount, waiting and subscribing on the given Scheduler
* @since 2.2.3 - experimental
* @see <a href="http://reactivex.io/documentation/operators/delay.html">ReactiveX operators documentation: Delay</a>
*/
@CheckReturnValue
@Experimental
@SchedulerSupport(SchedulerSupport.CUSTOM)
public final Completable delaySubscription(long delay, TimeUnit unit, Scheduler scheduler) {
return Completable.timer(delay, unit, scheduler).andThen(this);
}

/**
* Returns a Completable which calls the given onComplete callback if this Completable completes.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ public void checkParallelFlowable() {
addOverride(new ParamOverride(Completable.class, 0, ParamMode.ANY, "delay", Long.TYPE, TimeUnit.class, Scheduler.class));
addOverride(new ParamOverride(Completable.class, 0, ParamMode.ANY, "delay", Long.TYPE, TimeUnit.class, Scheduler.class, Boolean.TYPE));

// negative time is considered as zero time
addOverride(new ParamOverride(Completable.class, 0, ParamMode.ANY, "delaySubscription", Long.TYPE, TimeUnit.class));
addOverride(new ParamOverride(Completable.class, 0, ParamMode.ANY, "delaySubscription", Long.TYPE, TimeUnit.class, Scheduler.class));

// zero repeat is allowed
addOverride(new ParamOverride(Completable.class, 0, ParamMode.NON_NEGATIVE, "repeat", Long.TYPE));

Expand Down