@@ -11530,6 +11530,41 @@ public final Flowable<T> sample(long period, TimeUnit unit) {
11530
11530
return sample(period, unit, Schedulers.computation());
11531
11531
}
11532
11532
11533
+ /**
11534
+ * Returns a Flowable that emits the most recently emitted item (if any) emitted by the source Publisher
11535
+ * within periodic time intervals and optionally emit the very last upstream item when the upstream completes.
11536
+ * <p>
11537
+ * <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/sample.png" alt="">
11538
+ * <dl>
11539
+ * <dt><b>Backpressure:</b></dt>
11540
+ * <dd>This operator does not support backpressure as it uses time to control data flow.</dd>
11541
+ * <dt><b>Scheduler:</b></dt>
11542
+ * <dd>{@code sample} operates by default on the {@code computation} {@link Scheduler}.</dd>
11543
+ * </dl>
11544
+ *
11545
+ * @param period
11546
+ * the sampling rate
11547
+ * @param unit
11548
+ * the {@link TimeUnit} in which {@code period} is defined
11549
+ * @param emitLast
11550
+ * if true and the upstream completes while there is still an unsampled item available,
11551
+ * that item is emitted to downstream before completion
11552
+ * if false, an unsampled last item is ignored.
11553
+ * @return a Flowable that emits the results of sampling the items emitted by the source Publisher at
11554
+ * the specified time interval
11555
+ * @see <a href="http://reactivex.io/documentation/operators/sample.html">ReactiveX operators documentation: Sample</a>
11556
+ * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Backpressure">RxJava wiki: Backpressure</a>
11557
+ * @see #throttleLast(long, TimeUnit)
11558
+ * @since 2.0.5 - experimental
11559
+ */
11560
+ @CheckReturnValue
11561
+ @BackpressureSupport(BackpressureKind.ERROR)
11562
+ @SchedulerSupport(SchedulerSupport.COMPUTATION)
11563
+ @Experimental
11564
+ public final Flowable<T> sample(long period, TimeUnit unit, boolean emitLast) {
11565
+ return sample(period, unit, Schedulers.computation(), emitLast);
11566
+ }
11567
+
11533
11568
/**
11534
11569
* Returns a Flowable that emits the most recently emitted item (if any) emitted by the source Publisher
11535
11570
* within periodic time intervals, where the intervals are defined on a particular Scheduler.
@@ -11560,7 +11595,47 @@ public final Flowable<T> sample(long period, TimeUnit unit) {
11560
11595
public final Flowable<T> sample(long period, TimeUnit unit, Scheduler scheduler) {
11561
11596
ObjectHelper.requireNonNull(unit, "unit is null");
11562
11597
ObjectHelper.requireNonNull(scheduler, "scheduler is null");
11563
- return RxJavaPlugins.onAssembly(new FlowableSampleTimed<T>(this, period, unit, scheduler));
11598
+ return RxJavaPlugins.onAssembly(new FlowableSampleTimed<T>(this, period, unit, scheduler, false));
11599
+ }
11600
+
11601
+ /**
11602
+ * Returns a Flowable that emits the most recently emitted item (if any) emitted by the source Publisher
11603
+ * within periodic time intervals, where the intervals are defined on a particular Scheduler
11604
+ * and optionally emit the very last upstream item when the upstream completes.
11605
+ * <p>
11606
+ * <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/sample.s.png" alt="">
11607
+ * <dl>
11608
+ * <dt><b>Backpressure:</b></dt>
11609
+ * <dd>This operator does not support backpressure as it uses time to control data flow.</dd>
11610
+ * <dt><b>Scheduler:</b></dt>
11611
+ * <dd>You specify which {@link Scheduler} this operator will use</dd>
11612
+ * </dl>
11613
+ *
11614
+ * @param period
11615
+ * the sampling rate
11616
+ * @param unit
11617
+ * the {@link TimeUnit} in which {@code period} is defined
11618
+ * @param scheduler
11619
+ * the {@link Scheduler} to use when sampling
11620
+ * @param emitLast
11621
+ * if true and the upstream completes while there is still an unsampled item available,
11622
+ * that item is emitted to downstream before completion
11623
+ * if false, an unsampled last item is ignored.
11624
+ * @return a Flowable that emits the results of sampling the items emitted by the source Publisher at
11625
+ * the specified time interval
11626
+ * @see <a href="http://reactivex.io/documentation/operators/sample.html">ReactiveX operators documentation: Sample</a>
11627
+ * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Backpressure">RxJava wiki: Backpressure</a>
11628
+ * @see #throttleLast(long, TimeUnit, Scheduler)
11629
+ * @since 2.0.5 - experimental
11630
+ */
11631
+ @CheckReturnValue
11632
+ @BackpressureSupport(BackpressureKind.ERROR)
11633
+ @SchedulerSupport(SchedulerSupport.CUSTOM)
11634
+ @Experimental
11635
+ public final Flowable<T> sample(long period, TimeUnit unit, Scheduler scheduler, boolean emitLast) {
11636
+ ObjectHelper.requireNonNull(unit, "unit is null");
11637
+ ObjectHelper.requireNonNull(scheduler, "scheduler is null");
11638
+ return RxJavaPlugins.onAssembly(new FlowableSampleTimed<T>(this, period, unit, scheduler, emitLast));
11564
11639
}
11565
11640
11566
11641
/**
@@ -11590,7 +11665,44 @@ public final Flowable<T> sample(long period, TimeUnit unit, Scheduler scheduler)
11590
11665
@SchedulerSupport(SchedulerSupport.NONE)
11591
11666
public final <U> Flowable<T> sample(Publisher<U> sampler) {
11592
11667
ObjectHelper.requireNonNull(sampler, "sampler is null");
11593
- return RxJavaPlugins.onAssembly(new FlowableSamplePublisher<T>(this, sampler));
11668
+ return RxJavaPlugins.onAssembly(new FlowableSamplePublisher<T>(this, sampler, false));
11669
+ }
11670
+
11671
+ /**
11672
+ * Returns a Flowable that, when the specified {@code sampler} Publisher emits an item or completes,
11673
+ * emits the most recently emitted item (if any) emitted by the source Publisher since the previous
11674
+ * emission from the {@code sampler} Publisher
11675
+ * and optionally emit the very last upstream item when the upstream or other Publisher complete.
11676
+ * <p>
11677
+ * <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/sample.o.png" alt="">
11678
+ * <dl>
11679
+ * <dt><b>Backpressure:</b></dt>
11680
+ * <dd>This operator does not support backpressure as it uses the emissions of the {@code sampler}
11681
+ * Publisher to control data flow.</dd>
11682
+ * <dt><b>Scheduler:</b></dt>
11683
+ * <dd>This version of {@code sample} does not operate by default on a particular {@link Scheduler}.</dd>
11684
+ * </dl>
11685
+ *
11686
+ * @param <U> the element type of the sampler Publisher
11687
+ * @param sampler
11688
+ * the Publisher to use for sampling the source Publisher
11689
+ * @param emitLast
11690
+ * if true and the upstream completes while there is still an unsampled item available,
11691
+ * that item is emitted to downstream before completion
11692
+ * if false, an unsampled last item is ignored.
11693
+ * @return a Flowable that emits the results of sampling the items emitted by this Publisher whenever
11694
+ * the {@code sampler} Publisher emits an item or completes
11695
+ * @see <a href="http://reactivex.io/documentation/operators/sample.html">ReactiveX operators documentation: Sample</a>
11696
+ * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Backpressure">RxJava wiki: Backpressure</a>
11697
+ * @since 2.0.5 - experimental
11698
+ */
11699
+ @CheckReturnValue
11700
+ @BackpressureSupport(BackpressureKind.ERROR)
11701
+ @SchedulerSupport(SchedulerSupport.NONE)
11702
+ @Experimental
11703
+ public final <U> Flowable<T> sample(Publisher<U> sampler, boolean emitLast) {
11704
+ ObjectHelper.requireNonNull(sampler, "sampler is null");
11705
+ return RxJavaPlugins.onAssembly(new FlowableSamplePublisher<T>(this, sampler, emitLast));
11594
11706
}
11595
11707
11596
11708
/**
0 commit comments