@Override public void onResponse(final Response response) { if (notified.compareAndSet(false, true)) { if (timeout != null) { timeout.cancel(); } listener.onResponse(response); } }
@Override public void onFailure(Throwable t) { if (notified.compareAndSet(false, true)) { if (timeout != null) { timeout.cancel(); } listener.onFailure(t); } }
@Override public void run(Timeout timeout) throws Exception { if (timeout.isCancelled()) { return; } if (lifecycle.stoppedOrClosed()) { listener.onClose(); } else { listener.onTimeout(this.timeout); } // note, we rely on the listener to remove itself in case of timeout if needed }