本文整理了Java中io.reactivex.Flowable.sample()
方法的一些代码示例,展示了Flowable.sample()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.sample()
方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称: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
@Override
public Flowable<Object> apply(Flowable<Object> f)
throws Exception {
return f.sample(1, TimeUnit.SECONDS);
}
});
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void sampleUnitNull() {
just1.sample(1, null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void sampleFlowableNull() {
just1.sample(null);
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public Flowable<Object> apply(Flowable<Object> f)
throws Exception {
return f.sample(PublishProcessor.create());
}
});
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void sampleSchedulerNull() {
just1.sample(1, TimeUnit.SECONDS, null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void samplePublisherNull() {
just1.sample(null);
}
代码示例来源:origin: ReactiveX/RxJava
@SchedulerSupport(SchedulerSupport.COMPUTATION)
public final Flowable<T> throttleLast(long intervalDuration, TimeUnit unit) {
return sample(intervalDuration, unit);
代码示例来源:origin: ReactiveX/RxJava
@SchedulerSupport(SchedulerSupport.CUSTOM)
public final Flowable<T> throttleLast(long intervalDuration, TimeUnit unit, Scheduler scheduler) {
return sample(intervalDuration, unit, scheduler);
代码示例来源:origin: ReactiveX/RxJava
/**
* Returns a Flowable that emits the most recently emitted item (if any) emitted by the source Publisher
* within periodic time intervals.
* <p>
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/sample.png" alt="">
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>This operator does not support backpressure as it uses time to control data flow.</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code sample} operates by default on the {@code computation} {@link Scheduler}.</dd>
* </dl>
*
* @param period
* the sampling rate
* @param unit
* the {@link TimeUnit} in which {@code period} is defined
* @return a Flowable that emits the results of sampling the items emitted by the source Publisher at
* the specified time interval
* @see <a href="http://reactivex.io/documentation/operators/sample.html">ReactiveX operators documentation: Sample</a>
* @see <a href="https://github.com/ReactiveX/RxJava/wiki/Backpressure">RxJava wiki: Backpressure</a>
* @see #throttleLast(long, TimeUnit)
*/
@CheckReturnValue
@BackpressureSupport(BackpressureKind.ERROR)
@SchedulerSupport(SchedulerSupport.COMPUTATION)
public final Flowable<T> sample(long period, TimeUnit unit) {
return sample(period, unit, Schedulers.computation());
}
代码示例来源:origin: ReactiveX/RxJava
@SchedulerSupport(SchedulerSupport.COMPUTATION)
public final Flowable<T> sample(long period, TimeUnit unit, boolean emitLast) {
return sample(period, unit, Schedulers.computation(), emitLast);
代码示例来源:origin: redisson/redisson
@SchedulerSupport(SchedulerSupport.COMPUTATION)
public final Flowable<T> throttleLast(long intervalDuration, TimeUnit unit) {
return sample(intervalDuration, unit);
代码示例来源:origin: redisson/redisson
/**
* Returns a Flowable that emits the most recently emitted item (if any) emitted by the source Publisher
* within periodic time intervals.
* <p>
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/sample.png" alt="">
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>This operator does not support backpressure as it uses time to control data flow.</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code sample} operates by default on the {@code computation} {@link Scheduler}.</dd>
* </dl>
*
* @param period
* the sampling rate
* @param unit
* the {@link TimeUnit} in which {@code period} is defined
* @return a Flowable that emits the results of sampling the items emitted by the source Publisher at
* the specified time interval
* @see <a href="http://reactivex.io/documentation/operators/sample.html">ReactiveX operators documentation: Sample</a>
* @see <a href="https://github.com/ReactiveX/RxJava/wiki/Backpressure">RxJava wiki: Backpressure</a>
* @see #throttleLast(long, TimeUnit)
*/
@CheckReturnValue
@BackpressureSupport(BackpressureKind.ERROR)
@SchedulerSupport(SchedulerSupport.COMPUTATION)
public final Flowable<T> sample(long period, TimeUnit unit) {
return sample(period, unit, Schedulers.computation());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void emitLastTimed() {
Flowable.just(1)
.sample(1, TimeUnit.DAYS, true)
.test()
.assertResult(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void emitLastTimedEmpty() {
Flowable.empty()
.sample(1, TimeUnit.DAYS, true)
.test()
.assertResult();
}
代码示例来源:origin: redisson/redisson
@SchedulerSupport(SchedulerSupport.COMPUTATION)
public final Flowable<T> sample(long period, TimeUnit unit, boolean emitLast) {
return sample(period, unit, Schedulers.computation(), emitLast);
代码示例来源:origin: ReactiveX/RxJava
Flowable<Long> sampled = source.sample(400L, TimeUnit.MILLISECONDS, scheduler);
sampled.subscribe(subscriber);
代码示例来源:origin: ReactiveX/RxJava
@Test
public void emitLastOtherEmpty() {
Flowable.empty()
.sample(Flowable.timer(1, TimeUnit.DAYS), true)
.test()
.assertResult();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void emitLastOther() {
Flowable.just(1)
.sample(Flowable.timer(1, TimeUnit.DAYS), true)
.test()
.assertResult(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void error() {
Flowable.error(new TestException())
.sample(1, TimeUnit.SECONDS)
.test()
.assertFailure(TestException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void emitLastTimedCustomScheduler() {
Flowable.just(1)
.sample(1, TimeUnit.DAYS, Schedulers.single(), true)
.test()
.assertResult(1);
}
内容来源于网络,如有侵权,请联系作者删除!