Skip to main content

Future

Represents the result of an asynchronous operation that may not be available yet.

Future provides a way to access the result of asynchronous computations. It acts as a placeholder for a value that will be computed in the background by another thread. Futures enable non-blocking programming patterns where you can start an operation and continue with other work while waiting for the result. Aleph executes asynchronous work on a shared worker thread pool so launching many asynchronous operations does not create unbounded threads. The future can be queried to check if the result is ready, and the calling thread can block until the result becomes available.

Example


// Start an asynchronous operation
var future_result = async(fun() {
// Some time-consuming computation
return 5
})

// Do other work while computation runs in background
var x = 1

// Get the result (blocks if not ready yet)
var result = future_result.get()
print("Async result: ${result}")

Members

NameDescription
getRetrieves the value from the future, blocking if necessary.
validChecks if the future has a valid shared state.
waitBlocks until the future is ready.