io.reactivex.Flowable.sample()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(186)

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

Flowable.sample介绍

[英]Returns a Flowable that emits the most recently emitted item (if any) emitted by the source Publisher within periodic time intervals.

Backpressure: This operator does not support backpressure as it uses time to control data flow. Scheduler: sample operates by default on the computation Scheduler.
[中]返回在定期时间间隔内发出源发布服务器最近发出的项(如果有)的可流动项。
背压:此运算符不支持背压,因为它使用时间来控制数据流。调度程序:默认情况下,示例在计算调度程序上运行。

代码示例

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

  1. @Override
  2. public Flowable<Object> apply(Flowable<Object> f)
  3. throws Exception {
  4. return f.sample(1, TimeUnit.SECONDS);
  5. }
  6. });

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

  1. @Test(expected = NullPointerException.class)
  2. public void sampleUnitNull() {
  3. just1.sample(1, null);
  4. }

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

  1. @Test(expected = NullPointerException.class)
  2. public void sampleFlowableNull() {
  3. just1.sample(null);
  4. }

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

  1. @Override
  2. public Flowable<Object> apply(Flowable<Object> f)
  3. throws Exception {
  4. return f.sample(PublishProcessor.create());
  5. }
  6. });

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

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

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

  1. @Test(expected = NullPointerException.class)
  2. public void samplePublisherNull() {
  3. just1.sample(null);
  4. }

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

  1. @SchedulerSupport(SchedulerSupport.COMPUTATION)
  2. public final Flowable<T> throttleLast(long intervalDuration, TimeUnit unit) {
  3. return sample(intervalDuration, unit);

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

  1. @SchedulerSupport(SchedulerSupport.CUSTOM)
  2. public final Flowable<T> throttleLast(long intervalDuration, TimeUnit unit, Scheduler scheduler) {
  3. return sample(intervalDuration, unit, scheduler);

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

  1. /**
  2. * Returns a Flowable that emits the most recently emitted item (if any) emitted by the source Publisher
  3. * within periodic time intervals.
  4. * <p>
  5. * <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/sample.png" alt="">
  6. * <dl>
  7. * <dt><b>Backpressure:</b></dt>
  8. * <dd>This operator does not support backpressure as it uses time to control data flow.</dd>
  9. * <dt><b>Scheduler:</b></dt>
  10. * <dd>{@code sample} operates by default on the {@code computation} {@link Scheduler}.</dd>
  11. * </dl>
  12. *
  13. * @param period
  14. * the sampling rate
  15. * @param unit
  16. * the {@link TimeUnit} in which {@code period} is defined
  17. * @return a Flowable that emits the results of sampling the items emitted by the source Publisher at
  18. * the specified time interval
  19. * @see <a href="http://reactivex.io/documentation/operators/sample.html">ReactiveX operators documentation: Sample</a>
  20. * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Backpressure">RxJava wiki: Backpressure</a>
  21. * @see #throttleLast(long, TimeUnit)
  22. */
  23. @CheckReturnValue
  24. @BackpressureSupport(BackpressureKind.ERROR)
  25. @SchedulerSupport(SchedulerSupport.COMPUTATION)
  26. public final Flowable<T> sample(long period, TimeUnit unit) {
  27. return sample(period, unit, Schedulers.computation());
  28. }

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

  1. @SchedulerSupport(SchedulerSupport.COMPUTATION)
  2. public final Flowable<T> sample(long period, TimeUnit unit, boolean emitLast) {
  3. return sample(period, unit, Schedulers.computation(), emitLast);

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

  1. @SchedulerSupport(SchedulerSupport.COMPUTATION)
  2. public final Flowable<T> throttleLast(long intervalDuration, TimeUnit unit) {
  3. return sample(intervalDuration, unit);

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

  1. /**
  2. * Returns a Flowable that emits the most recently emitted item (if any) emitted by the source Publisher
  3. * within periodic time intervals.
  4. * <p>
  5. * <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/sample.png" alt="">
  6. * <dl>
  7. * <dt><b>Backpressure:</b></dt>
  8. * <dd>This operator does not support backpressure as it uses time to control data flow.</dd>
  9. * <dt><b>Scheduler:</b></dt>
  10. * <dd>{@code sample} operates by default on the {@code computation} {@link Scheduler}.</dd>
  11. * </dl>
  12. *
  13. * @param period
  14. * the sampling rate
  15. * @param unit
  16. * the {@link TimeUnit} in which {@code period} is defined
  17. * @return a Flowable that emits the results of sampling the items emitted by the source Publisher at
  18. * the specified time interval
  19. * @see <a href="http://reactivex.io/documentation/operators/sample.html">ReactiveX operators documentation: Sample</a>
  20. * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Backpressure">RxJava wiki: Backpressure</a>
  21. * @see #throttleLast(long, TimeUnit)
  22. */
  23. @CheckReturnValue
  24. @BackpressureSupport(BackpressureKind.ERROR)
  25. @SchedulerSupport(SchedulerSupport.COMPUTATION)
  26. public final Flowable<T> sample(long period, TimeUnit unit) {
  27. return sample(period, unit, Schedulers.computation());
  28. }

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

  1. @Test
  2. public void emitLastTimed() {
  3. Flowable.just(1)
  4. .sample(1, TimeUnit.DAYS, true)
  5. .test()
  6. .assertResult(1);
  7. }

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

  1. @Test
  2. public void emitLastTimedEmpty() {
  3. Flowable.empty()
  4. .sample(1, TimeUnit.DAYS, true)
  5. .test()
  6. .assertResult();
  7. }

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

  1. @SchedulerSupport(SchedulerSupport.COMPUTATION)
  2. public final Flowable<T> sample(long period, TimeUnit unit, boolean emitLast) {
  3. return sample(period, unit, Schedulers.computation(), emitLast);

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

  1. Flowable<Long> sampled = source.sample(400L, TimeUnit.MILLISECONDS, scheduler);
  2. sampled.subscribe(subscriber);

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

  1. @Test
  2. public void emitLastOtherEmpty() {
  3. Flowable.empty()
  4. .sample(Flowable.timer(1, TimeUnit.DAYS), true)
  5. .test()
  6. .assertResult();
  7. }

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

  1. @Test
  2. public void emitLastOther() {
  3. Flowable.just(1)
  4. .sample(Flowable.timer(1, TimeUnit.DAYS), true)
  5. .test()
  6. .assertResult(1);
  7. }

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

  1. @Test
  2. public void error() {
  3. Flowable.error(new TestException())
  4. .sample(1, TimeUnit.SECONDS)
  5. .test()
  6. .assertFailure(TestException.class);
  7. }

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

  1. @Test
  2. public void emitLastTimedCustomScheduler() {
  3. Flowable.just(1)
  4. .sample(1, TimeUnit.DAYS, Schedulers.single(), true)
  5. .test()
  6. .assertResult(1);
  7. }

相关文章

Flowable类方法