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

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

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

Flowable.throttleLast介绍

[英]Returns a Flowable that emits only the last item emitted by the source Publisher during sequential time windows of a specified duration.

This differs from #throttleFirst in that this ticks along at a scheduled interval whereas #throttleFirst does not tick, it just tracks the passage of time.

Backpressure: This operator does not support backpressure as it uses time to control data flow. Scheduler: throttleLast operates by default on the computation Scheduler.
[中]返回在指定持续时间的连续时间窗口内仅发出源发布服务器发出的最后一项的可流动项。
这与#throttleFirst的不同之处在于,它以预定的间隔滴答作响,而#throttleFirst不滴答作响,它只是跟踪时间的流逝。
背压:此运算符不支持背压,因为它使用时间来控制数据流。调度器:throttleLast默认在计算调度器上运行。

代码示例

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

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

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

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

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

  1. @Test
  2. public void testSampleUnsubscribe() {
  3. final Subscription s = mock(Subscription.class);
  4. Flowable<Integer> f = Flowable.unsafeCreate(
  5. new Publisher<Integer>() {
  6. @Override
  7. public void subscribe(Subscriber<? super Integer> subscriber) {
  8. subscriber.onSubscribe(s);
  9. }
  10. }
  11. );
  12. f.throttleLast(1, TimeUnit.MILLISECONDS).subscribe().dispose();
  13. verify(s).cancel();
  14. }

代码示例来源:origin: TeamNewPipe/NewPipe

  1. protected void setupNotification() {
  2. notificationManager = NotificationManagerCompat.from(this);
  3. notificationBuilder = createNotification();
  4. startForeground(getNotificationId(), notificationBuilder.build());
  5. final Function<Flowable<String>, Publisher<String>> throttleAfterFirstEmission = flow -> flow.limit(1)
  6. .concatWith(flow.skip(1).throttleLast(NOTIFICATION_SAMPLING_PERIOD, TimeUnit.MILLISECONDS));
  7. disposables.add(notificationUpdater
  8. .filter(s -> !s.isEmpty())
  9. .publish(throttleAfterFirstEmission)
  10. .observeOn(AndroidSchedulers.mainThread())
  11. .subscribe(this::updateNotification));
  12. }

代码示例来源:origin: android10/Android-ReactiveProgramming

  1. @OnClick(R.id.btn_backpressureThrottleLast) void onBackpressureThrottleLast() {
  2. dataManager.milliseconds(10000)
  3. .throttleLast(10, TimeUnit.MILLISECONDS)
  4. .observeOn(AndroidSchedulers.mainThread())
  5. .subscribeOn(Schedulers.computation());
  6. //.subscribe(new BackpressureSubscriber<>(this, getString(R.string.btn_text_backpressure_throttleLast)));
  7. }

代码示例来源:origin: laizimo/richeditor

  1. public static Flowable<BaseUploadBean> generateFlowable(@NonNull RequestBodyWrapper uploadBeanEmitter, final String filePath){
  2. Flowable<BaseUploadBean> flowable = uploadBeanEmitter.getUploadProcessor()
  3. .publish()
  4. .autoConnect();
  5. return flowable
  6. .throttleLast(100, TimeUnit.MILLISECONDS).mergeWith(flowable.takeLast(1))
  7. .subscribeOn(Schedulers.io())
  8. .observeOn(AndroidSchedulers.mainThread());
  9. }

代码示例来源:origin: akarnokd/akarnokd-misc

  1. private static void test(String tag) {
  2. System.out.println("before " + tag);
  3. Flowable<Integer> fa = Flowable.<Integer>generate(emitter -> emitter.onNext(1))
  4. .doOnSubscribe(v -> System.out.println("Sub A " + tag))
  5. //.compose(pingPongOn(Schedulers.computation()))
  6. .observeOn(Schedulers.computation())
  7. .throttleLast(1, TimeUnit.SECONDS, Schedulers.single())
  8. .doOnNext(v -> System.out.println("a: " + v + " " + tag))
  9. ;
  10. Flowable<Integer> fb = Flowable.<Integer>generate(emitter -> emitter.onNext(2))
  11. .doOnSubscribe(v -> System.out.println("Sub B " + tag))
  12. // .compose(pingPongOn(Schedulers.computation()))
  13. .observeOn(Schedulers.computation())
  14. .throttleLast(1, TimeUnit.SECONDS, Schedulers.single())
  15. .doOnNext(v -> System.out.println("b: " + v + " " + tag))
  16. ;
  17. Flowable.combineLatest(fa, fb, (a, b) -> a - b)
  18. // .subscribeOn(Schedulers.computation())
  19. .subscribe(c -> {
  20. System.out.println("c: " + c + " " + tag);
  21. });
  22. System.out.println("after " + tag);
  23. }

相关文章

Flowable类方法