示例#1
0
  @Test
  public void testInterruptTerminalEventAwaitTimed() {
    TestSubscriber<Integer> ts = TestSubscriber.create();

    final Thread t0 = Thread.currentThread();
    Worker w = Schedulers.computation().createWorker();
    try {
      w.schedule(
          new Action0() {
            @Override
            public void call() {
              t0.interrupt();
            }
          },
          200,
          TimeUnit.MILLISECONDS);

      try {
        ts.awaitTerminalEvent(5, TimeUnit.SECONDS);
        fail("Did not interrupt wait!");
      } catch (RuntimeException ex) {
        if (!(ex.getCause() instanceof InterruptedException)) {
          fail("The cause is not InterruptedException! " + ex.getCause());
        }
      }
    } finally {
      w.unsubscribe();
    }
  }
示例#2
0
  @Test
  public void testInterruptTerminalEventAwaitAndUnsubscribe() {
    TestSubscriber<Integer> ts = TestSubscriber.create();

    final Thread t0 = Thread.currentThread();
    Worker w = Schedulers.computation().createWorker();
    try {
      w.schedule(
          new Action0() {
            @Override
            public void call() {
              t0.interrupt();
            }
          },
          200,
          TimeUnit.MILLISECONDS);

      ts.awaitTerminalEventAndUnsubscribeOnTimeout(5, TimeUnit.SECONDS);
      if (!ts.isUnsubscribed()) {
        fail("Did not unsubscribe!");
      }
    } finally {
      w.unsubscribe();
    }
  }
 @Override
 public void onCompleted() {
   try {
     inner.unsubscribe();
     List<T> toEmit;
     synchronized (this) {
       if (done) {
         return;
       }
       done = true;
       toEmit = chunk;
       chunk = null;
     }
     child.onNext(toEmit);
   } catch (Throwable t) {
     child.onError(t);
     return;
   }
   child.onCompleted();
   unsubscribe();
 }