如何在rx-java中触发反压

时间:2017-07-10 10:20:13

标签: rx-java

rx-java version:2.1.1

  public static void main(String[] args) {
    Integer[] ints = new Integer[100000];
    Arrays.fill(ints, 1);
    Flowable.fromArray(ints).onBackpressureBuffer(1, () -> {
      System.out.println("Overflow");
    }).subscribe(events -> {
      Thread.sleep(1000);
      System.out.println(events);
    });
  }

缓慢的消费者和相当小的缓冲容量不会触发溢出操作。为什么呢?

1 个答案:

答案 0 :(得分:1)

我认为这是因为你只使用一个线程,运算符通常应用当前线程,如果没有明确指定。在订阅之前尝试添加subscribeOn export default { props:['service', 'method', 'id'], methods: { destroy() { var self = this; swal({ title: 'Weet u het zeker?', type: 'warning', showCancelButton: true, confirmButtonText: 'Ja verwijder', cancelButtonText: 'Stop!', confirmButtonColor: '#34495e', cancelButtonColor: '#ff3860', }).then (() => { self.service[self.method](self.id) .then(() => { swal({ title: 'Verwijderd', text: 'Succesvol verwijderd', type: 'success', showConfirmButton: false, timer: 2000 }); location.reload(); }) .catch(() => { swal({ title: 'Fout', text: 'Heeft u voldoende rechten?', type: 'error', showConfirmButton: false, timer: 2000 }); }); }) } } }