Async-runtime-state-new
Construct an AsyncRuntimeState snapshot from explicit runtime mode and worker-support values. This is the low-level constructor behind the public async runtime state shape used in diagnostics.
Interface
pub fn AsyncRuntimeState::new(
mode : AsyncRuntimeMode,
background_worker : Bool,
) -> AsyncRuntimeState {input
mode : AsyncRuntimeMode- Backend-specific async runtime mode such asNativeWorkerorCompatibility.background_worker : Bool- Whether native-style background-worker support is available.
output
AsyncRuntimeState- Runtime state snapshot containing the supplied mode and worker-support flag.
Explanation
Detailed rules explaining key parameters and behaviors
- This constructor simply packages
modeandbackground_workerinto one public snapshot value. - It does not query the current backend automatically.
async_runtime_state()is the higher-level API that reads these values from the live runtime environment.- It also does not validate whether the supplied pair matches the current backend contract.
- The supplied
modeandbackground_workervalues are stored exactly as provided; this constructor does not recompute, normalize, or cross-check either field. - The constructed value matches the same public shape used by async runtime serializers.
- Because
AsyncRuntimeStateis only a data snapshot type, this constructor is mainly useful for tests, adapters, and synthetic diagnostics rather than ordinary runtime probing.
How to Use
Here are some specific examples provided.
When Need A Hand-built Runtime Snapshot
When tests or adapters should construct a runtime state explicitly:
let runtime = AsyncRuntimeState::new(
AsyncRuntimeMode::Compatibility,
false,
)In this example, the runtime snapshot is built directly without probing the active backend.
When Need Structured Runtime Diagnostics Input
When code should prepare a runtime state value before serialization:
let runtime = AsyncRuntimeState::new(async_runtime_mode(), async_runtime_supports_background_worker())In this example, callers still use the direct constructor while keeping the data source explicit.
Error Case
e.g.:
This constructor itself does not have a normal failure mode; it only packages the provided values.
If callers want the current backend snapshot directly,
async_runtime_state()is the simpler API.If callers manually pair
NativeWorkerwithfalseorCompatibilitywithtrue, the constructor still accepts that snapshot because it does not enforce backend consistency.If callers want the currently probed runtime pair instead of a synthetic one, they must pass
async_runtime_mode()plusasync_runtime_supports_background_worker()explicitly or useasync_runtime_state().
Notes
Use this helper when code should construct an
AsyncRuntimeStatevalue explicitly.Pair it with
AsyncLoggerState::new(...)when assembling a full async logger snapshot by hand.Prefer
async_runtime_state()when the goal is to report the actual current backend pair rather than an arbitrary constructed snapshot.