io.reactivex.Observable.timestamp()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(146)

本文整理了Java中io.reactivex.Observable.timestamp()方法的一些代码示例,展示了Observable.timestamp()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.timestamp()方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:timestamp

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

  1. /**
  2. * Returns an Observable that emits each item emitted by the source ObservableSource, wrapped in a
  3. * {@link Timed} object whose timestamps are provided by a specified Scheduler.
  4. * <p>
  5. * <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timestamp.s.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>This operator does not operate on any particular scheduler but uses the current time
  9. * from the specified {@link Scheduler}.</dd>
  10. * </dl>
  11. *
  12. * @param scheduler
  13. * the {@link Scheduler} to use as a time source
  14. * @return an Observable that emits timestamped items from the source ObservableSource with timestamps provided by
  15. * the {@code scheduler}
  16. * @see <a href="http://reactivex.io/documentation/operators/timestamp.html">ReactiveX operators documentation: Timestamp</a>
  17. */
  18. @CheckReturnValue
  19. @SchedulerSupport(SchedulerSupport.NONE) // Supplied scheduler is only used for creating timestamps.
  20. public final Observable<Timed<T>> timestamp(Scheduler scheduler) {
  21. return timestamp(TimeUnit.MILLISECONDS, scheduler);
  22. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test(expected = NullPointerException.class)
  2. public void timestampSchedulerNull() {
  3. just1.timestamp(TimeUnit.SECONDS, null);
  4. }

代码示例来源:origin: ReactiveX/RxJava

  1. /**
  2. * Returns an Observable that emits each item emitted by the source ObservableSource, wrapped in a
  3. * {@link Timed} object.
  4. * <p>
  5. * <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timestamp.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code timestamp} does not operate on any particular scheduler but uses the current time
  9. * from the {@code computation} {@link Scheduler}.</dd>
  10. * </dl>
  11. *
  12. * @return an Observable that emits timestamped items from the source ObservableSource
  13. * @see <a href="http://reactivex.io/documentation/operators/timestamp.html">ReactiveX operators documentation: Timestamp</a>
  14. */
  15. @CheckReturnValue
  16. @SchedulerSupport(SchedulerSupport.NONE)
  17. public final Observable<Timed<T>> timestamp() {
  18. return timestamp(TimeUnit.MILLISECONDS, Schedulers.computation());
  19. }

代码示例来源:origin: ReactiveX/RxJava

  1. /**
  2. * Returns an Observable that emits each item emitted by the source ObservableSource, wrapped in a
  3. * {@link Timed} object.
  4. * <p>
  5. * <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timestamp.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code timestamp} does not operate on any particular scheduler but uses the current time
  9. * from the {@code computation} {@link Scheduler}.</dd>
  10. * </dl>
  11. *
  12. * @param unit the time unit for the current time
  13. * @return an Observable that emits timestamped items from the source ObservableSource
  14. * @see <a href="http://reactivex.io/documentation/operators/timestamp.html">ReactiveX operators documentation: Timestamp</a>
  15. */
  16. @CheckReturnValue
  17. @SchedulerSupport(SchedulerSupport.NONE)
  18. public final Observable<Timed<T>> timestamp(TimeUnit unit) {
  19. return timestamp(unit, Schedulers.computation());
  20. }

代码示例来源:origin: redisson/redisson

  1. /**
  2. * Returns an Observable that emits each item emitted by the source ObservableSource, wrapped in a
  3. * {@link Timed} object whose timestamps are provided by a specified Scheduler.
  4. * <p>
  5. * <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timestamp.s.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>This operator does not operate on any particular scheduler but uses the current time
  9. * from the specified {@link Scheduler}.</dd>
  10. * </dl>
  11. *
  12. * @param scheduler
  13. * the {@link Scheduler} to use as a time source
  14. * @return an Observable that emits timestamped items from the source ObservableSource with timestamps provided by
  15. * the {@code scheduler}
  16. * @see <a href="http://reactivex.io/documentation/operators/timestamp.html">ReactiveX operators documentation: Timestamp</a>
  17. */
  18. @CheckReturnValue
  19. @SchedulerSupport(SchedulerSupport.NONE) // Supplied scheduler is only used for creating timestamps.
  20. public final Observable<Timed<T>> timestamp(Scheduler scheduler) {
  21. return timestamp(TimeUnit.MILLISECONDS, scheduler);
  22. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test(expected = NullPointerException.class)
  2. public void timestampUnitNull() {
  3. just1.timestamp(null, Schedulers.single());
  4. }

代码示例来源:origin: redisson/redisson

  1. /**
  2. * Returns an Observable that emits each item emitted by the source ObservableSource, wrapped in a
  3. * {@link Timed} object.
  4. * <p>
  5. * <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timestamp.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code timestamp} does not operate on any particular scheduler but uses the current time
  9. * from the {@code computation} {@link Scheduler}.</dd>
  10. * </dl>
  11. *
  12. * @return an Observable that emits timestamped items from the source ObservableSource
  13. * @see <a href="http://reactivex.io/documentation/operators/timestamp.html">ReactiveX operators documentation: Timestamp</a>
  14. */
  15. @CheckReturnValue
  16. @SchedulerSupport(SchedulerSupport.NONE)
  17. public final Observable<Timed<T>> timestamp() {
  18. return timestamp(TimeUnit.MILLISECONDS, Schedulers.computation());
  19. }

代码示例来源:origin: redisson/redisson

  1. /**
  2. * Returns an Observable that emits each item emitted by the source ObservableSource, wrapped in a
  3. * {@link Timed} object.
  4. * <p>
  5. * <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timestamp.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code timestamp} does not operate on any particular scheduler but uses the current time
  9. * from the {@code computation} {@link Scheduler}.</dd>
  10. * </dl>
  11. *
  12. * @param unit the time unit for the current time
  13. * @return an Observable that emits timestamped items from the source ObservableSource
  14. * @see <a href="http://reactivex.io/documentation/operators/timestamp.html">ReactiveX operators documentation: Timestamp</a>
  15. */
  16. @CheckReturnValue
  17. @SchedulerSupport(SchedulerSupport.NONE)
  18. public final Observable<Timed<T>> timestamp(TimeUnit unit) {
  19. return timestamp(unit, Schedulers.computation());
  20. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void timeIntervalDefaultSchedulerCustomUnit() {
  3. final TestScheduler scheduler = new TestScheduler();
  4. RxJavaPlugins.setComputationSchedulerHandler(new Function<Scheduler, Scheduler>() {
  5. @Override
  6. public Scheduler apply(Scheduler v) throws Exception {
  7. return scheduler;
  8. }
  9. });
  10. try {
  11. Observable.range(1, 5)
  12. .timestamp(TimeUnit.SECONDS)
  13. .map(new Function<Timed<Integer>, Long>() {
  14. @Override
  15. public Long apply(Timed<Integer> v) throws Exception {
  16. return v.time();
  17. }
  18. })
  19. .test()
  20. .assertResult(0L, 0L, 0L, 0L, 0L);
  21. } finally {
  22. RxJavaPlugins.reset();
  23. }
  24. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void timeIntervalDefault() {
  3. final TestScheduler scheduler = new TestScheduler();
  4. RxJavaPlugins.setComputationSchedulerHandler(new Function<Scheduler, Scheduler>() {
  5. @Override
  6. public Scheduler apply(Scheduler v) throws Exception {
  7. return scheduler;
  8. }
  9. });
  10. try {
  11. Observable.range(1, 5)
  12. .timestamp()
  13. .map(new Function<Timed<Integer>, Long>() {
  14. @Override
  15. public Long apply(Timed<Integer> v) throws Exception {
  16. return v.time();
  17. }
  18. })
  19. .test()
  20. .assertResult(0L, 0L, 0L, 0L, 0L);
  21. } finally {
  22. RxJavaPlugins.reset();
  23. }
  24. }

代码示例来源:origin: diabolicallabs/vertx-cron

  1. public static Observable<Timed<Long>> cronspec(Scheduler scheduler, String cronspec, String timeZoneName) {
  2. if (timeZoneName != null) {
  3. Boolean noneMatch = Arrays.stream(TimeZone.getAvailableIDs()).noneMatch(available -> available.equals(timeZoneName));
  4. if (noneMatch) throw new IllegalArgumentException("timeZoneName " + timeZoneName + " is invalid");
  5. }
  6. return Observable.just(cronspec)
  7. .flatMap(_cronspec -> {
  8. CronExpression cron;
  9. try {
  10. cron = new CronExpression(_cronspec);
  11. if (timeZoneName != null) {
  12. cron.setTimeZone(TimeZone.getTimeZone(timeZoneName));
  13. }
  14. } catch (ParseException e) {
  15. throw new IllegalArgumentException("Invalid cronspec " + _cronspec, e);
  16. }
  17. return Observable.just(cron)
  18. .map(cronExpression -> cronExpression.getNextValidTimeAfter(new Date(new Date().getTime() + 500)))
  19. .map(nextRunDate -> nextRunDate.getTime() - new Date().getTime())
  20. .flatMap(delay -> Observable.timer(delay, TimeUnit.MILLISECONDS, scheduler))
  21. .timestamp()
  22. .repeat();
  23. });
  24. }

相关文章

Observable类方法