FutureObserver extends CountDownLatch implements Observer<T>, Future<T>, Disposable { @Override public boolean cancel(boolean mayInterruptIfRunning) { for (;;) { Disposable a = s.get(); if (a == this || a == DisposableHelper.DISPOSED) { return false; } if (s.compareAndSet(a, DisposableHelper.DISPOSED)) { if (a != null) { a.dispose(); } countDown(); return true; } } } FutureObserver(); @Override boolean cancel(boolean mayInterruptIfRunning); @Override boolean isCancelled(); @Override boolean isDone(); @Override T get(); @Override T get(long timeout, TimeUnit unit); @Override void onSubscribe(Disposable s); @Override void onNext(T t); @Override void onError(Throwable t); @Override void onComplete(); @Override void dispose(); @Override boolean isDisposed();  }
@Test public void cancelRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final FutureSubscriber<Integer> fo = new FutureSubscriber<Integer>(); Runnable r = new Runnable() { @Override public void run() { fo.cancel(false); } }; TestHelper.race(r, r); } }