concurrent / org.apache.tuweni.concurrent / CompletableAsyncResult

CompletableAsyncResult

interface CompletableAsyncResult<T : Any> : AsyncResult<T> (source)

An AsyncResult that can be later completed successfully with a provided value, or completed with an exception.

Parameters

- The type of the value returned by this result.

Functions

complete

abstract fun complete(value: T?): Boolean

Complete this result with the given value.

completeExceptionally

abstract fun completeExceptionally(ex: Throwable): Boolean

Complete this result with the given exception.

Inherited Functions

accept

abstract fun accept(consumer: BiConsumer<in T, Throwable>): AsyncCompletion

Returns a new completion that, when this result completes either normally or exceptionally, completes after executing the supplied function with this result's value and exception as arguments.

Either the value or the exception supplied to the function will be null.

cancel

abstract fun cancel(): Boolean

Attempt to cancel execution of this task.

This attempt will fail if the task has already completed, has already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started when cancel is called, this task should never run.

After this method returns, subsequent calls to #isDone() will always return true. Subsequent calls to #isCancelled() will always return true if this method returned true.

exceptionally

abstract fun exceptionally(fn: Function<Throwable, out T>): AsyncResult<T>

Returns a new result that, when this result completes exceptionally, completes with the value obtained from executing the supplied function with this result's exception as an argument. Otherwise, if this result completes normally, then the returned result also completes normally with the same value.

get

abstract fun get(): T?

Waits if necessary for the computation to complete, and then retrieves its result.

abstract fun get(timeout: Long, unit: TimeUnit): T?

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result.

handle

abstract fun <U : Any> handle(fn: BiFunction<in T, Throwable, out U>): AsyncResult<U>

Returns a new result that, when this result completes either normally or exceptionally, completes with the value obtained from executing the supplied function with this result's value and exception as arguments.

Either the value or the exception supplied to the function will be null.

isCancelled

abstract fun isCancelled(): Boolean

Returns true if this task was cancelled before it completed normally.

isCompletedExceptionally

abstract fun isCompletedExceptionally(): Boolean

Returns true if completed exceptionally or cancelled.

isDone

abstract fun isDone(): Boolean

Returns true if completed normally, completed exceptionally or cancelled.

then

abstract fun <U : Any> then(fn: Function<in T, out AsyncResult<U>>): AsyncResult<U>

Returns a new result that, when this result completes normally, completes with the same value or exception as the result returned after executing the given function with this results value as an argument.

thenAccept

abstract fun thenAccept(consumer: Consumer<in T>): AsyncCompletion

Returns a completion that, when this result completes normally, completes after executing the supplied consumer with this result's value as an argument.

thenAcceptBoth

abstract fun <U : Any> thenAcceptBoth(other: AsyncResult<out U>, consumer: BiConsumer<in T, in U>): AsyncCompletion

Returns a completion that, when this result and the other result both complete normally, completes after executing the supplied consumer with both this result's value and the value from the other result as arguments.

thenApply

abstract fun <U : Any> thenApply(fn: Function<in T, out U>): AsyncResult<U>

Returns a result that, when this result completes normally, completes with the value obtained from executing the supplied function with this result's value as an argument.

thenCombine

abstract fun <U : Any, V : Any> thenCombine(other: AsyncResult<out U>, fn: BiFunction<in T, in U, out V>): AsyncResult<V>

Returns a result that, when this result and the other result both complete normally, completes with the value obtained from executing the supplied function with both this result's value and the value from the other result as arguments.

thenCompose

abstract fun thenCompose(fn: Function<in T, out AsyncCompletion>): AsyncCompletion

When this result completes normally, invokes the given function with the resulting value and obtains a new AsyncCompletion.

thenRun

abstract fun thenRun(runnable: Runnable): AsyncCompletion

Returns a new completion that, when this result completes normally, completes after given action is executed.

thenSchedule

abstract fun <U : Any> thenSchedule(vertx: Vertx, fn: Function<in T, out AsyncResult<U>>): AsyncResult<U>

Returns a new result that, when this result completes normally, completes with the same value or exception as the completion returned after executing the given function on the vertx context with this results value as an argument.

thenScheduleApply

abstract fun <U : Any> thenScheduleApply(vertx: Vertx, fn: Function<in T, out U>): AsyncResult<U>

Returns a result that, when this result completes normally, completes with the value obtained from executing the supplied function on the vertx context with this result's value as an argument.

thenScheduleBlockingApply

abstract fun <U : Any> thenScheduleBlockingApply(vertx: Vertx, fn: Function<in T, out U>): AsyncResult<U>

Returns a result that, when this result completes normally, completes with the value obtained from executing the supplied blocking function on the vertx context with this result's value as an argument.

abstract fun <U : Any> thenScheduleBlockingApply(executor: WorkerExecutor, fn: Function<in T, out U>): AsyncResult<U>

Returns a result that, when this result completes normally, completes with the value obtained from executing the supplied blocking function on the vertx executor with this result's value as an argument.

thenScheduleBlockingRun

abstract fun thenScheduleBlockingRun(vertx: Vertx, runnable: Runnable): AsyncCompletion

Returns a new completion that, when this result completes normally, completes after the given blocking action is executed on the vertx context.

abstract fun thenScheduleBlockingRun(executor: WorkerExecutor, runnable: Runnable): AsyncCompletion

Returns a new completion that, when this result completes normally, completes after the given blocking action is executed on the vertx executor.

thenScheduleRun

abstract fun thenScheduleRun(vertx: Vertx, runnable: Runnable): AsyncCompletion

Returns a new completion that, when this result completes normally, completes after the given action is executed on the vertx context.

whenComplete

abstract fun whenComplete(action: BiConsumer<in T, in Throwable>): AsyncResult<T>

Returns a new result that completes with the same value or exception as this result, after executing the given action with this result's value or exception.

Either the value or the exception supplied to the action will be null.