/** * Add a cancellation handler. The argument will be cancelled whenever this {@code IoFuture} is cancelled. If * the {@code IoFuture} is already cancelled when this method is called, the handler will be called directly. * * @param cancellable the cancel handler */ protected void addCancelHandler(final Cancellable cancellable) { State<T> oldState, newState; do { oldState = getState(); if (oldState.getStatus() != Status.WAITING || oldState.cancelRequested()) { try { cancellable.cancel(); } catch (Throwable ignored) { } return; } newState = oldState.withCancelHandler(cancellable); if (oldState == newState) return; } while (! compareAndSetState(oldState, newState)); }
/** * Cancel an operation. The actual cancel may be synchronous or asynchronous. Implementers will use this method * to initiate the cancel; use the {@link #setCancelled()} method to indicate that the cancel was successful. The * default implementation calls any registered cancel handlers. * * @return this {@code IoFuture} instance */ public IoFuture<T> cancel() { State<T> state; do { state = getState(); if (state.getStatus() != Status.WAITING || state.cancelRequested()) return this; } while (! compareAndSetState(state, new CancelRequestedState<T>(state))); state.cancel(); return this; }
boolean cancelRequested() { return next.cancelRequested(); } }
boolean cancelRequested() { return next.cancelRequested(); } }
boolean cancelRequested() { return next.cancelRequested(); } }
/** * Add a cancellation handler. The argument will be cancelled whenever this {@code IoFuture} is cancelled. If * the {@code IoFuture} is already cancelled when this method is called, the handler will be called directly. * * @param cancellable the cancel handler */ protected void addCancelHandler(final Cancellable cancellable) { State<T> oldState, newState; do { oldState = getState(); if (oldState.getStatus() != Status.WAITING || oldState.cancelRequested()) { try { cancellable.cancel(); } catch (Throwable ignored) { } return; } newState = oldState.withCancelHandler(cancellable); if (oldState == newState) return; } while (! compareAndSetState(oldState, newState)); }
/** * Cancel an operation. The actual cancel may be synchronous or asynchronous. Implementers will use this method * to initiate the cancel; use the {@link #setCancelled()} method to indicate that the cancel was successful. The * default implementation calls any registered cancel handlers. * * @return this {@code IoFuture} instance */ public IoFuture<T> cancel() { State<T> state; do { state = getState(); if (state.getStatus() != Status.WAITING || state.cancelRequested()) return this; } while (! compareAndSetState(state, new CancelRequestedState<T>(state))); state.cancel(); return this; }
boolean cancelRequested() { return next.cancelRequested(); } }
boolean cancelRequested() { return next.cancelRequested(); } }
boolean cancelRequested() { return next.cancelRequested(); } }