@Test public void unsubscribeTwiceDoesNotRunTwice() { final AtomicInteger called = new AtomicInteger(0); Disposable disposable = new AbstractDisposeOnMainThread() { @Override protected void onDispose() { called.incrementAndGet(); } }; disposable.dispose(); disposable.dispose(); disposable.dispose(); assertEquals(1, called.get()); }
@Override public final void dispose() { if (unsubscribed.compareAndSet(false, true)) { if (Looper.myLooper() == Looper.getMainLooper()) { onDispose(); } else { AndroidInteropSchedulers.mainThread().scheduleDirect(new Runnable() { @Override public void run() { onDispose(); } }); } } }
AbstractDisposeOnMainThread implements Disposable { @Override public final void dispose() { if (unsubscribed.compareAndSet(false, true)) { if (Looper.myLooper() == Looper.getMainLooper()) { onDispose(); } else { AndroidInteropSchedulers.mainThread().scheduleDirect(new Runnable() { @Override public void run() { onDispose(); } }); } } } }
AbstractDisposeOnMainThread implements Disposable { @Override public final void dispose() { if (unsubscribed.compareAndSet(false, true)) { if (Looper.myLooper() == Looper.getMainLooper()) { onDispose(); } else { AndroidInteropSchedulers.mainThread().scheduleDirect(new Runnable() { @Override public void run() { onDispose(); } }); } } }  }
AbstractDisposeOnMainThread implements Disposable { @Override public final void dispose() { if (unsubscribed.compareAndSet(false, true)) { if (Looper.myLooper() == Looper.getMainLooper()) { onDispose(); } else { AndroidInteropSchedulers.mainThread().scheduleDirect(new Runnable() { @Override public void run() { onDispose(); } }); } } }  static void verifyMainThread(); @Override final boolean isDisposed(); @Override final void dispose(); }
AbstractDisposeOnMainThread implements Disposable { @Override public final void dispose() { if (unsubscribed.compareAndSet(false, true)) { if (Looper.myLooper() == Looper.getMainLooper()) { onDispose(); } else { AndroidInteropSchedulers.mainThread().scheduleDirect(new Runnable() { @Override public void run() { onDispose(); } }); } } }  static void verifyMainThread(); @Override final boolean isDisposed(); @Override final void dispose();  }