Skip to content

Async

This guide is a short orientation to Zynx async. The normative language semantics live in the Async language chapter, and the API surface lives in std.async.

Zynx async is cold and future-based. Calling a Future-returning function evaluates its arguments immediately, captures them into a suspended future, and does not run the body. Work starts only when the future is consumed by await or a structured future API.

Quick Example

Zynx
import std.async;

fn work() -> ^Future<i32> {
	return 42;
}

fn main() {
	let f: ^Future<i32> = work(); // body has not run yet
	let value = await f;        // starts and joins work
}

Contract Summary

  • Declare async work by returning the canonical Future<T> from std.async; use async.Future<T> when the module-qualified form is clearer.
  • await is valid in any function body; it starts the future if needed, drives it to completion, and yields T.
  • Bare future expressions are rejected; consume each future with await, a structured API, or std.drop.
  • The async surface has no public unstructured background API. Use await, async.all, async.race, async.timeout, or async.Group<T, E> to make concurrency explicit and scoped.

Next Steps

  • Async Semantics: cold futures, await, structured concurrency, groups, cancellation, channel choice, and reference rules.
  • std.async: Future<T>, Task<T>, Group<T, E>, Parallel<T, E>, and AsyncError.
  • Concurrency And Parallelism: the runtime model, structured parallelism, channels, and the shared-memory primitives.

Released under the MIT License.