本文整理了Java中io.reactivex.Observable.timeInterval()
方法的一些代码示例,展示了Observable.timeInterval()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.timeInterval()
方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:timeInterval
[英]Returns an Observable that emits records of the time interval between consecutive items emitted by the source ObservableSource.
Scheduler: timeInterval does not operate on any particular scheduler but uses the current time from the computation Scheduler.
[中]返回一个Observable,该Observable发出源ObservableSource发出的连续项之间的时间间隔记录。
调度器:timeInterval不在任何特定的调度器上运行,而是使用计算调度器中的当前时间。
代码示例来源:origin: ReactiveX/RxJava
@Override
public Observable<Timed<Object>> apply(Observable<Object> f)
throws Exception {
return f.timeInterval();
}
});
代码示例来源:origin: ReactiveX/RxJava
/**
* Returns an Observable that emits records of the time interval between consecutive items emitted by the
* source ObservableSource, where this interval is computed on a specified Scheduler.
* <p>
* <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timeInterval.s.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The operator does not operate on any particular scheduler but uses the current time
* from the specified {@link Scheduler}.</dd>
* </dl>
*
* @param scheduler
* the {@link Scheduler} used to compute time intervals
* @return an Observable that emits time interval information items
* @see <a href="http://reactivex.io/documentation/operators/timeinterval.html">ReactiveX operators documentation: TimeInterval</a>
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE) // Supplied scheduler is only used for creating timestamps.
public final Observable<Timed<T>> timeInterval(Scheduler scheduler) {
return timeInterval(TimeUnit.MILLISECONDS, scheduler);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void timeIntervalSchedulerNull() {
just1.timeInterval(TimeUnit.SECONDS, null);
}
代码示例来源:origin: ReactiveX/RxJava
/**
* Returns an Observable that emits records of the time interval between consecutive items emitted by the
* source ObservableSource.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timeInterval.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code timeInterval} does not operate on any particular scheduler but uses the current time
* from the {@code computation} {@link Scheduler}.</dd>
* </dl>
*
* @return an Observable that emits time interval information items
* @see <a href="http://reactivex.io/documentation/operators/timeinterval.html">ReactiveX operators documentation: TimeInterval</a>
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Observable<Timed<T>> timeInterval() {
return timeInterval(TimeUnit.MILLISECONDS, Schedulers.computation());
}
代码示例来源:origin: ReactiveX/RxJava
/**
* Returns an Observable that emits records of the time interval between consecutive items emitted by the
* source ObservableSource.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timeInterval.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code timeInterval} does not operate on any particular scheduler but uses the current time
* from the {@code computation} {@link Scheduler}.</dd>
* </dl>
*
* @param unit the time unit for the current time
* @return an Observable that emits time interval information items
* @see <a href="http://reactivex.io/documentation/operators/timeinterval.html">ReactiveX operators documentation: TimeInterval</a>
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Observable<Timed<T>> timeInterval(TimeUnit unit) {
return timeInterval(unit, Schedulers.computation());
}
代码示例来源:origin: redisson/redisson
/**
* Returns an Observable that emits records of the time interval between consecutive items emitted by the
* source ObservableSource, where this interval is computed on a specified Scheduler.
* <p>
* <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timeInterval.s.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The operator does not operate on any particular scheduler but uses the current time
* from the specified {@link Scheduler}.</dd>
* </dl>
*
* @param scheduler
* the {@link Scheduler} used to compute time intervals
* @return an Observable that emits time interval information items
* @see <a href="http://reactivex.io/documentation/operators/timeinterval.html">ReactiveX operators documentation: TimeInterval</a>
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE) // Supplied scheduler is only used for creating timestamps.
public final Observable<Timed<T>> timeInterval(Scheduler scheduler) {
return timeInterval(TimeUnit.MILLISECONDS, scheduler);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void dispose() {
TestHelper.checkDisposed(Observable.just(1).timeInterval());
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void timeIntervalUnitNull() {
just1.timeInterval(null, Schedulers.single());
}
代码示例来源:origin: redisson/redisson
/**
* Returns an Observable that emits records of the time interval between consecutive items emitted by the
* source ObservableSource.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timeInterval.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code timeInterval} does not operate on any particular scheduler but uses the current time
* from the {@code computation} {@link Scheduler}.</dd>
* </dl>
*
* @return an Observable that emits time interval information items
* @see <a href="http://reactivex.io/documentation/operators/timeinterval.html">ReactiveX operators documentation: TimeInterval</a>
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Observable<Timed<T>> timeInterval() {
return timeInterval(TimeUnit.MILLISECONDS, Schedulers.computation());
}
代码示例来源:origin: redisson/redisson
/**
* Returns an Observable that emits records of the time interval between consecutive items emitted by the
* source ObservableSource.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timeInterval.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code timeInterval} does not operate on any particular scheduler but uses the current time
* from the {@code computation} {@link Scheduler}.</dd>
* </dl>
*
* @param unit the time unit for the current time
* @return an Observable that emits time interval information items
* @see <a href="http://reactivex.io/documentation/operators/timeinterval.html">ReactiveX operators documentation: TimeInterval</a>
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Observable<Timed<T>> timeInterval(TimeUnit unit) {
return timeInterval(unit, Schedulers.computation());
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void error() {
Observable.error(new TestException())
.timeInterval()
.test()
.assertFailure(TestException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void timeIntervalDefault() {
final TestScheduler scheduler = new TestScheduler();
RxJavaPlugins.setComputationSchedulerHandler(new Function<Scheduler, Scheduler>() {
@Override
public Scheduler apply(Scheduler v) throws Exception {
return scheduler;
}
});
try {
Observable.range(1, 5)
.timeInterval()
.map(new Function<Timed<Integer>, Long>() {
@Override
public Long apply(Timed<Integer> v) throws Exception {
return v.time();
}
})
.test()
.assertResult(0L, 0L, 0L, 0L, 0L);
} finally {
RxJavaPlugins.reset();
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void timeIntervalDefaultSchedulerCustomUnit() {
final TestScheduler scheduler = new TestScheduler();
RxJavaPlugins.setComputationSchedulerHandler(new Function<Scheduler, Scheduler>() {
@Override
public Scheduler apply(Scheduler v) throws Exception {
return scheduler;
}
});
try {
Observable.range(1, 5)
.timeInterval(TimeUnit.SECONDS)
.map(new Function<Timed<Integer>, Long>() {
@Override
public Long apply(Timed<Integer> v) throws Exception {
return v.time();
}
})
.test()
.assertResult(0L, 0L, 0L, 0L, 0L);
} finally {
RxJavaPlugins.reset();
}
}
代码示例来源:origin: sunfusheng/Gank.IO
private void prepareForExiting() {
lifecycle.throttleFirst(END_TIME_SECONDS, TimeUnit.SECONDS, AndroidSchedulers.mainThread())
.subscribe(it -> ToastUtil.toast(R.string.exit_tip), Throwable::printStackTrace);
lifecycle.compose(bindToLifecycle())
.timeInterval(AndroidSchedulers.mainThread())
.skip(1)
.filter(it -> it.time(TimeUnit.SECONDS) < END_TIME_SECONDS)
.subscribe(it -> finish(), Throwable::printStackTrace);
}
代码示例来源:origin: AppStoreFoundation/asf-sdk
private Observable<PaymentDetails> getPayment(String skuId) {
return Observable.interval(0, period, TimeUnit.SECONDS, scheduler)
.timeInterval()
.switchMap(scan -> paymentService.getPaymentDetails(skuId))
.takeUntil(paymentDetails -> paymentDetails.getTransaction()
.getStatus() == Status.ACCEPTED);
}
内容来源于网络,如有侵权,请联系作者删除!