Documentation channel: current development main at compiler checkpoint 1d7e15e. The latest tagged release is v0.0.3; pages identify APIs that are not yet released.
Async
Strut supports async functions, futures, await, and async lambdas. Async functions and async lambdas run on Strut's shared multithreaded executor. Independent ready tasks can execute concurrently across worker threads.
Async functions
Prefix a function declaration with async. Calling it returns a future for the declared result type.
async function answer() -> int {
return 42;
}
Awaiting a result
function main() -> int {
pending := answer();
value := await pending;
print(value);
return 0;
}
Async lambdas
Async lambdas use the same lambda syntax with an async prefix.
add := async (int x, int y) => x + y;
Async block lambdas
load := async (string path) => {
print("loading " + path);
return path;
};
Error propagation
Errors raised by asynchronous work are retained by the future and surface when the result is awaited.
Executor behaviour
The executor owns a pool of native worker threads and wakes workers as tasks become ready. await retrieves a future result and rethrows asynchronous failures on the awaiting thread.
Long-running blocking work can occupy an executor worker, so explicitly blocking workloads should use Strut's thread/process facilities or dedicated blocking APIs rather than relying on async as a disguise for blocking work.
