本文整理了Java中io.reactivex.Observable.timestamp()
方法的一些代码示例,展示了Observable.timestamp()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.timestamp()
方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:timestamp
[英]Returns an Observable that emits each item emitted by the source ObservableSource, wrapped in a Timed object.
Scheduler: timestamp does not operate on any particular scheduler but uses the current time from the computation Scheduler.
[中]返回一个Observable,它将发射源ObservableSource发出的每个项,并封装在一个定时对象中。
调度器:时间戳不在任何特定的调度器上运行,而是使用计算调度器中的当前时间。
代码示例来源:origin: ReactiveX/RxJava
/**
* Returns an Observable that emits each item emitted by the source ObservableSource, wrapped in a
* {@link Timed} object whose timestamps are provided by a specified Scheduler.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timestamp.s.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>This 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} to use as a time source
* @return an Observable that emits timestamped items from the source ObservableSource with timestamps provided by
* the {@code scheduler}
* @see <a href="http://reactivex.io/documentation/operators/timestamp.html">ReactiveX operators documentation: Timestamp</a>
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE) // Supplied scheduler is only used for creating timestamps.
public final Observable<Timed<T>> timestamp(Scheduler scheduler) {
return timestamp(TimeUnit.MILLISECONDS, scheduler);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void timestampSchedulerNull() {
just1.timestamp(TimeUnit.SECONDS, null);
}
代码示例来源:origin: ReactiveX/RxJava
/**
* Returns an Observable that emits each item emitted by the source ObservableSource, wrapped in a
* {@link Timed} object.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timestamp.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code timestamp} 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 timestamped items from the source ObservableSource
* @see <a href="http://reactivex.io/documentation/operators/timestamp.html">ReactiveX operators documentation: Timestamp</a>
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Observable<Timed<T>> timestamp() {
return timestamp(TimeUnit.MILLISECONDS, Schedulers.computation());
}
代码示例来源:origin: ReactiveX/RxJava
/**
* Returns an Observable that emits each item emitted by the source ObservableSource, wrapped in a
* {@link Timed} object.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timestamp.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code timestamp} 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 timestamped items from the source ObservableSource
* @see <a href="http://reactivex.io/documentation/operators/timestamp.html">ReactiveX operators documentation: Timestamp</a>
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Observable<Timed<T>> timestamp(TimeUnit unit) {
return timestamp(unit, Schedulers.computation());
}
代码示例来源:origin: redisson/redisson
/**
* Returns an Observable that emits each item emitted by the source ObservableSource, wrapped in a
* {@link Timed} object whose timestamps are provided by a specified Scheduler.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timestamp.s.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>This 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} to use as a time source
* @return an Observable that emits timestamped items from the source ObservableSource with timestamps provided by
* the {@code scheduler}
* @see <a href="http://reactivex.io/documentation/operators/timestamp.html">ReactiveX operators documentation: Timestamp</a>
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE) // Supplied scheduler is only used for creating timestamps.
public final Observable<Timed<T>> timestamp(Scheduler scheduler) {
return timestamp(TimeUnit.MILLISECONDS, scheduler);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void timestampUnitNull() {
just1.timestamp(null, Schedulers.single());
}
代码示例来源:origin: redisson/redisson
/**
* Returns an Observable that emits each item emitted by the source ObservableSource, wrapped in a
* {@link Timed} object.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timestamp.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code timestamp} 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 timestamped items from the source ObservableSource
* @see <a href="http://reactivex.io/documentation/operators/timestamp.html">ReactiveX operators documentation: Timestamp</a>
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Observable<Timed<T>> timestamp() {
return timestamp(TimeUnit.MILLISECONDS, Schedulers.computation());
}
代码示例来源:origin: redisson/redisson
/**
* Returns an Observable that emits each item emitted by the source ObservableSource, wrapped in a
* {@link Timed} object.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timestamp.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code timestamp} 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 timestamped items from the source ObservableSource
* @see <a href="http://reactivex.io/documentation/operators/timestamp.html">ReactiveX operators documentation: Timestamp</a>
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Observable<Timed<T>> timestamp(TimeUnit unit) {
return timestamp(unit, Schedulers.computation());
}
代码示例来源: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)
.timestamp(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: 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)
.timestamp()
.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: diabolicallabs/vertx-cron
public static Observable<Timed<Long>> cronspec(Scheduler scheduler, String cronspec, String timeZoneName) {
if (timeZoneName != null) {
Boolean noneMatch = Arrays.stream(TimeZone.getAvailableIDs()).noneMatch(available -> available.equals(timeZoneName));
if (noneMatch) throw new IllegalArgumentException("timeZoneName " + timeZoneName + " is invalid");
}
return Observable.just(cronspec)
.flatMap(_cronspec -> {
CronExpression cron;
try {
cron = new CronExpression(_cronspec);
if (timeZoneName != null) {
cron.setTimeZone(TimeZone.getTimeZone(timeZoneName));
}
} catch (ParseException e) {
throw new IllegalArgumentException("Invalid cronspec " + _cronspec, e);
}
return Observable.just(cron)
.map(cronExpression -> cronExpression.getNextValidTimeAfter(new Date(new Date().getTime() + 500)))
.map(nextRunDate -> nextRunDate.getTime() - new Date().getTime())
.flatMap(delay -> Observable.timer(delay, TimeUnit.MILLISECONDS, scheduler))
.timestamp()
.repeat();
});
}
内容来源于网络,如有侵权,请联系作者删除!