Skip to main content

Module host

Module host 

Source
Expand description

The ambient transport: what an action talks to, and where it is kept.

§Why it is ambient

The host assembles the execution context for every call itself, so an action has nothing to pass it and no reason to carry a context parameter down through its own functions.

What remains is a transport, and there is exactly one of it per run. It lives in a slot crate::run fills before the handler is called, so crate::graphql can reach it without an argument and without a handle.

§Two slots, because there are two worlds

Under wasm32 the guest is single-threaded, the transport is the real ABI, and a OnceLock fails safe in both directions that matter: a second set answers Err instead of corrupting, and a read before the first set is None — a typed error rather than a panic.

Off wasm32 — which is cargo test, on the developer’s own machine — the transport is whatever a test installed, tests run in parallel threads, and a thread_local! is the only honest home for it.

The split is by target, not by cfg(test). cfg(test) is set only while this crate’s own tests build; an action crate running cargo test sees this crate compiled without it. Splitting by target is what puts the seam in the crate an action depends on, which is the audience it exists for.

Traits§

Transport
What an action can ask of its host.