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

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

本文整理了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

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

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

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

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

@Test
public void testSampleUnsubscribe() {
  final Subscription s = mock(Subscription.class);
  Flowable<Integer> f = Flowable.unsafeCreate(
      new Publisher<Integer>() {
        @Override
        public void subscribe(Subscriber<? super Integer> subscriber) {
          subscriber.onSubscribe(s);
        }
      }
  );
  f.throttleLast(1, TimeUnit.MILLISECONDS).subscribe().dispose();
  verify(s).cancel();
}

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

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

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

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

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

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

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

private static void test(String tag) {
    System.out.println("before " + tag);
    Flowable<Integer> fa = Flowable.<Integer>generate(emitter -> emitter.onNext(1))
        .doOnSubscribe(v -> System.out.println("Sub A " + tag))
        //.compose(pingPongOn(Schedulers.computation()))
        .observeOn(Schedulers.computation())
        .throttleLast(1, TimeUnit.SECONDS, Schedulers.single())
        .doOnNext(v -> System.out.println("a: " + v + " " + tag))
        ;
    
    Flowable<Integer> fb = Flowable.<Integer>generate(emitter -> emitter.onNext(2))
        .doOnSubscribe(v -> System.out.println("Sub B " + tag))
//                .compose(pingPongOn(Schedulers.computation()))
        .observeOn(Schedulers.computation())
        .throttleLast(1, TimeUnit.SECONDS, Schedulers.single())
        .doOnNext(v -> System.out.println("b: " + v + " " + tag))
        ;
    Flowable.combineLatest(fa, fb, (a, b) -> a - b)
//                .subscribeOn(Schedulers.computation())
        .subscribe(c -> {
          System.out.println("c: " + c + " " + tag);
        });
    System.out.println("after " + tag);
  }

相关文章

Flowable类方法