Promise

class Promise<V, E>(val thread: ThreadRef) : Future<V, E>

Represents an ongoing asynchronous operation.

Promise implements the Future interface, which means it can be returned from functions performing asynchronous operations to provide callers a flexible way to wait for the response.

Constructors

Link copied to clipboard
constructor(thread: ThreadRef)

Properties

Link copied to clipboard
open override val thread: ThreadRef

Functions

Link copied to clipboard
open suspend fun await(): V

Wait for the Future to complete using Kotlin Coroutines, and throw a VoiceException if the operation failed.

Link copied to clipboard
open suspend fun awaitNoThrow(): Result<V, E>

Wait for the Future to complete using Kotlin Coroutines. Will return errors rather than throwing an exception.

Link copied to clipboard
open fun <V2> chain(action: (V) -> Future<V2, E>): Future<V2, E>

When this Future completes, run another async operation.

Link copied to clipboard
open fun logError(tag: String, description: String): Future<V, E>

If this operation fails, log an error.

Link copied to clipboard
open fun <V2> map(filter: (V) -> V2): Future<V2, E>

If the Future returns successfully, transform the result to another type.

Link copied to clipboard
open fun <E2> mapError(filter: (E) -> E2): Future<V, E2>

If the Future returns an error, transform the error to another type.

Link copied to clipboard
fun resolve(value: Result<V, E>)

Resolve the promise, notifying any pending callbacks.

Link copied to clipboard
fun resolveErr(error: E)

Convenience method to resolve a promise with an error.

Link copied to clipboard
fun resolveOk(value: V)

Convenience method to resolve a promise with a success value.

Link copied to clipboard
open override fun withCallback(callback: ResultCallback<V, E>): Future<V, E>

Give a callback when the Future completes.

Link copied to clipboard
open fun withErrorCallback(callback: Callback<E>): Future<V, E>

Give a callback if the Future returns an error.

Link copied to clipboard

Returns a new Future which times out after the specified duration.