本文整理了Java中rx.Observable.delaySubscription()
方法的一些代码示例,展示了Observable.delaySubscription()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.delaySubscription()
方法的具体详情如下:
包路径:rx.Observable
类名称:Observable
方法名:delaySubscription
[英]Returns an Observable that delays the subscription to the source Observable by a given amount of time.
Scheduler: This version of delay operates by default on the compuation Scheduler.
[中]返回一个Observable,它将订阅源Observable延迟一段给定的时间。
调度程序:默认情况下,此版本的延迟在计算调度程序上运行。
代码示例来源:origin: leeowenowen/rxjava-examples
@Override
public void run() {
Observable.just(1, 2)
.delaySubscription(2, TimeUnit.SECONDS)
.subscribe(new Action1<Integer>() {
@Override
public void call(Integer integer) {
log(integer);
}
});
}
});
代码示例来源:origin: groupon/grox
private Observable<Integer> getColorFromServer() {
final Observable<Integer> result;
if (random.nextInt() % ERROR_RATE == 0) {
result = error(new RuntimeException(ERROR_MSG));
} else {
final int red = random.nextInt(MAX_COLOR);
final int green = random.nextInt(MAX_COLOR);
final int blue = random.nextInt(MAX_COLOR);
final int color = rgb(red, green, blue);
result = just(color);
}
return result.delaySubscription(LATENCY_IN_MS, TimeUnit.MILLISECONDS);
}
}
代码示例来源:origin: com.netflix.rxjava/rxjava-core
/**
* Returns an Observable that delays the subscription to the source Observable by a given amount of time.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/delaySubscription.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>This version of {@code delay} operates by default on the {@code compuation} {@link Scheduler}.</dd>
* </dl>
*
* @param delay
* the time to delay the subscription
* @param unit
* the time unit of {@code delay}
* @return an Observable that delays the subscription to the source Observable by the given amount
* @see <a href="https://github.com/Netflix/RxJava/wiki/Observable-Utility-Operators#delaysubscription">RxJava wiki: delaySubscription</a>
*/
public final Observable<T> delaySubscription(long delay, TimeUnit unit) {
return delaySubscription(delay, unit, Schedulers.computation());
}
代码示例来源:origin: cookpad/RxT4A
@Test
public void shouldNotCallOnSubscribeWhenSubscriptionUnsubscribedBeforeDelay() {
Observable.OnSubscribe<Integer> onSubscribe = mock(Observable.OnSubscribe.class);
Handler handler = spy(new Handler());
final Worker worker = spy(new HandlerScheduler.HandlerWorker(handler));
Scheduler scheduler = new Scheduler() {
@Override
public Worker createWorker() {
return worker;
}
};
Subscription subscription = Observable.create(onSubscribe)
.delaySubscription(1, MINUTES, scheduler)
.subscribe();
verify(worker).schedule(any(Action0.class), eq(1L), eq(MINUTES));
verify(handler).postDelayed(any(Runnable.class), eq(MINUTES.toMillis(1)));
subscription.unsubscribe();
ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
verify(onSubscribe, never()).call(any(Subscriber.class));
verify(handler).removeCallbacks(any(Runnable.class));
}
}
代码示例来源:origin: com.netflix.iep/iep-rxhttp
@Override
public Observable<HttpClientResponse<ByteBuf>> call(HttpClientResponse<ByteBuf> res) {
final int code = res.getStatus().code();
Observable<HttpClientResponse<ByteBuf>> resObs;
if (code == 429 || code == 503) {
final long retryDelay = getRetryDelay(res, delay);
res.getContent().subscribe();
context.entry().withAttempt(attempt);
resObs = context.rxHttp().execute(context);
if (retryDelay > 0) {
resObs = resObs.delaySubscription(retryDelay, TimeUnit.MILLISECONDS);
}
} else if (code >= 500) {
res.getContent().subscribe();
context.entry().withAttempt(attempt);
resObs = context.rxHttp().execute(context);
} else {
resObs = Observable.just(res);
}
return resObs;
}
}
内容来源于网络,如有侵权,请联系作者删除!