Async-runtime-mode
Read the current backend-specific async runtime mode. This API is the narrowest capability probe when you only care whether the current build is running native worker semantics or compatibility behavior.
Interface
pub fn async_runtime_mode() -> AsyncRuntimeMode {}input
none- No arguments are required.
output
AsyncRuntimeMode- EitherNativeWorkerorCompatibility.
Explanation
Detailed rules explaining key parameters and behaviors
- The return value is determined by the active backend implementation.
NativeWorkeris the expected mode on native-style backends, whileCompatibilityis the expected mode on targets without native background-worker semantics.async_runtime_mode_label(...)converts the enum into a stable string value.async_runtime_supports_background_worker()is a narrower boolean probe built on the same idea.async_runtime_state()packages this mode together with the current background-worker capability into oneAsyncRuntimeStatesnapshot.- In the current backend implementations,
NativeWorkerpairs withbackground_worker=trueandCompatibilitypairs withbackground_worker=false. - Concretely, the native runtime entrypoint returns
native_worker_async_runtime_mode(), while the compatibility stub returnscompatibility_async_runtime_mode(). - The enum is therefore selected directly by the active backend helper on each call rather than read back out of a cached runtime snapshot object.
- This API is intentionally small and useful for lightweight branching.
- The mode result describes runtime behavior only; it should not be read as proof that every backend has been equally re-verified in the current release cycle.
How to Use
Here are some specific examples provided.
When Need A Small Capability Branch
When behavior should differ between native worker mode and compatibility mode:
match async_runtime_mode() {
AsyncRuntimeMode::NativeWorker => println("native worker")
AsyncRuntimeMode::Compatibility => println("compat")
}In this example, the branch is explicit and readable.
When Need Stable String Output
When the mode should be included in logs or telemetry labels:
println(async_runtime_mode_label(async_runtime_mode()))In this example, the output becomes a stable string instead of an enum pattern-match requirement.
Error Case
e.g.:
This API does not have a normal runtime failure mode; it reflects the compiled backend behavior.
If callers need the current mode paired with the matching worker-support flag, prefer a fresh
async_runtime_state()call instead of combiningasync_runtime_mode()with an older saved runtime snapshot.If you need worker support as a direct boolean, use
async_runtime_supports_background_worker()instead.
Notes
Use this API for minimal mode branching.
Use
async_runtime_state()when you also want worker support packaged into one object.Use
async_runtime_mode_label(...)when the result should leave enum space and become stable text such asnative_workerorcompatibility.This mode distinction is about runtime behavior, not whether
src-asyncitself is expected to compile for the target.See target-verification.md for the current verification status of individual targets.