tuweni / org.apache.tuweni.concurrent / AsyncResult

AsyncResult

interface AsyncResult<T : Any> (source)

A result that will be available at a future time.

Parameters

- The type of the result object.

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.

allOf

open static fun allOf(vararg rs: AsyncResult<*>): AsyncCompletion
open static fun allOf(rs: MutableCollection<out AsyncResult<*>>): AsyncCompletion
open static fun allOf(rs: Stream<out AsyncResult<*>>): AsyncCompletion

Returns an AsyncCompletion that completes when all of the given results complete. If any results 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.

combine

open static fun <T : Any> combine(rs: MutableCollection<out AsyncResult<out T>>): AsyncResult<MutableList<T>>
open static fun <T : Any> combine(rs: Stream<out AsyncResult<out T>>): AsyncResult<MutableList<T>>

Returns a result that completes when all of the given results complete. If any results complete exceptionally, then the resulting completion also completes exceptionally.

completed

open static fun <T : Any> completed(value: T?): AsyncResult<T>

Return an already completed result containing the given value.

exceptional

open static fun <T : Any> exceptional(ex: Throwable): AsyncResult<T>

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

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.

executeBlocking

open static fun <T : Any> executeBlocking(fn: Supplier<T>): AsyncResult<T>

Returns a result that, after the given blocking function executes asynchronously on ForkJoinPool#commonPool() and returns a result, completes when the returned result completes, with the same value or exception.

open static fun <T : Any> executeBlocking(executor: Executor, fn: Supplier<T>): AsyncResult<T>

Returns a result that, after the given blocking function executes asynchronously on an Executor and returns a result, completes when the returned result completes, with the same value or exception.

open static fun <T : Any> executeBlocking(vertx: Vertx, fn: Supplier<T>): AsyncResult<T>

Returns a result that, after the given blocking function executes asynchronously on a vertx context and returns a result, completes when the returned result completes, with the same value or exception.

open static fun <T : Any> executeBlocking(executor: WorkerExecutor, fn: Supplier<T>): AsyncResult<T>

Returns a result that, after the given blocking function executes asynchronously on a vertx executor and returns a result, completes when the returned result completes, with the same value or exception.

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.

incomplete

open static fun <T : Any> incomplete(): CompletableAsyncResult<T>

Return an incomplete result, 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.

runOnContext

open static fun <T : Any> runOnContext(vertx: Vertx, fn: Supplier<out AsyncResult<T>>): AsyncResult<T>

Returns a result that, after the given function executes on a vertx context and returns a result, completes when the returned result completes, with the same value or exception.

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

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.

Extension Functions

asDeferred

fun <T> AsyncResult<T>.asDeferred(): Deferred<T>

Converts this AsyncResult to an instance of Deferred. The AsyncResult is cancelled when the resulting deferred is cancelled.

await

suspend fun <T> AsyncResult<T>.await(): T

Awaits for completion of the AsyncResult without blocking a thread.

Inheritors

CompletableAsyncResult

interface CompletableAsyncResult<T : Any> : AsyncResult<T>

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