Interface ListenableFuture<V>

  • All Superinterfaces:
    Future<V>, Future<V>
    All Known Implementing Classes:
    SettableFuture

    public interface ListenableFuture<V>
    extends Future<V>
    Extend Future with the capability to accept completion callbacks. If the future has completed when the callback is added, the callback is triggered immediately.

    Inspired by com.google.common.util.concurrent.ListenableFuture.

    • Method Detail

      • addListener

        void addListener​(@NonNull
                         Runnable listener,
                         @NonNull
                         Executor executor)
        Registers a listener to be run. The listener will be run on the specified executor either when the Future's computation is complete or, if the computation is already complete, immediately. There is no guaranteed ordering of execution of listeners, but any listener added through this method is guaranteed to be called once the computation is complete. Exceptions thrown by a listener will be propagated up to the executor. Any exception thrown during Executor.execute(Runnable) (e.g., a RejectedExecutionException or an exception thrown by direct execution) will be caught and logged.
        Parameters:
        listener - the listener to execute.
        executor - the executor to run the listener in.