concurrent / org.apache.tuweni.concurrent / AsyncCompletion

AsyncCompletion

interface AsyncCompletion (source)

A completion that will be complete at a future time.

Properties

COMPLETED

static val COMPLETED: AsyncCompletion

Functions

accept

abstract fun accept(consumer: Consumer<in Throwable>): AsyncCompletion

Returns a new completion that completes successfully, after executing the given function with this completion's exception (if any).

The exception supplied to the function will be null if this completion completes successfully.

allOf

open static fun allOf(vararg cs: AsyncCompletion): AsyncCompletion
open static fun allOf(cs: MutableCollection<AsyncCompletion>): AsyncCompletion
open static fun allOf(cs: Stream<AsyncCompletion>): AsyncCompletion

Returns an AsyncCompletion that completes when all of the given completions complete. If any completions complete exceptionally, then the resulting completion also completes exceptionally.

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.

completed

open static fun completed(): AsyncCompletion

Return an already completed completion.

exceptional

open static fun exceptional(ex: Throwable): AsyncCompletion

Return an already failed completion, caused by the given exception.

exceptionally

abstract fun exceptionally(consumer: Consumer<in Throwable>): AsyncCompletion

Returns a new completion that, when this result completes exceptionally, completes after executing the supplied function. Otherwise, if this result completes normally, then the returned result also completes normally with the same value.

executeBlocking

open static fun executeBlocking(action: Runnable): AsyncCompletion

Returns a completion that completes after the given blocking action executes asynchronously on ForkJoinPool#commonPool().

open static fun executeBlocking(executor: Executor, action: Runnable): AsyncCompletion

Returns a completion that completes after the given blocking action executes asynchronously on an Executor.

open static fun executeBlocking(vertx: Vertx, action: Runnable): AsyncCompletion

Returns a completion that completes after the given blocking action executes asynchronously on a vertx context.

open static fun executeBlocking(executor: WorkerExecutor, action: Runnable): AsyncCompletion

Returns a completion that completes after the given blocking action executes asynchronously on a vertx executor.

handle

abstract fun <U : Any> handle(fn: Function<in 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 exception (if any) as an argument.

The exception supplied to the function will be null if this completion completes successfully.

incomplete

open static fun incomplete(): CompletableAsyncCompletion

Return an incomplete completion, that can be later completed or failed.

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.

join

abstract fun join(): Unit

Waits if necessary for the computation to complete.

abstract fun join(timeout: Long, unit: TimeUnit): Unit

Waits if necessary for at most the given time for the computation to complete.

runOnContext

open static fun runOnContext(vertx: Vertx, fn: Supplier<out AsyncCompletion>): AsyncCompletion

Returns a completion that, after the given function executes on a vertx context and returns a completion, completes when the completion from the function does.

open static fun runOnContext(vertx: Vertx, action: Runnable): AsyncCompletion

Returns a completion that completes after the given action executes on a vertx context.

Note that the given function is run directly on the context and should not block.

then

abstract fun <U : Any> then(fn: Supplier<out AsyncResult<U>>): AsyncResult<U>

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

thenApply

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

Returns a result that, when this completion and the other result both complete normally, completes with the value obtained from executing the supplied function with the value from the other result as an argument.

thenCombine

abstract fun thenCombine(other: AsyncCompletion): AsyncCompletion

Returns a completion that completes when both this completion and the other complete normally.

thenCompose

abstract fun thenCompose(fn: Supplier<out AsyncCompletion>): AsyncCompletion

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

thenConsume

abstract fun <U : Any> thenConsume(other: AsyncResult<out U>, consumer: Consumer<in U>): AsyncCompletion

Returns a completion that, when this completion and the supplied result both complete normally, completes after executing the supplied function with the value from the supplied result as an argument.

thenRun

abstract fun thenRun(runnable: Runnable): AsyncCompletion

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

thenSchedule

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

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

thenScheduleBlockingRun

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

Returns a new completion that, when this completion 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 completion 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 completion completes normally, completes after the given action is executed on the vertx context.

thenSupply

abstract fun <U : Any> thenSupply(supplier: Supplier<out U>): AsyncResult<U>

Returns a completion that, when this result completes normally, completes with the value obtained after executing the supplied function.

abstract fun <U : Any> thenSupply(vertx: Vertx, supplier: Supplier<out U>): AsyncResult<U>

Returns a completion that, when this result completes normally, completes with the value obtained after executing the supplied function on the vertx context.

whenComplete

abstract fun whenComplete(consumer: Consumer<in Throwable>): AsyncCompletion

Returns a new completion that completes in the same manner as this completion, after executing the given function with this completion's exception (if any).

The exception supplied to the function will be null if this completion completes successfully.

Inheritors

CompletableAsyncCompletion

interface CompletableAsyncCompletion : AsyncCompletion

An AsyncCompletion that can later be completed successfully or with a provided exception.