Skip to content

Async-runtime-state-type ​

AsyncRuntimeState is the public snapshot type used to describe backend-level async runtime capability. It is a direct alias to the async runtime state model returned by async_runtime_state() and used by async diagnostics serializers.

Interface ​

moonbit
pub type AsyncRuntimeState = @utils.AsyncRuntimeState

output ​

  • AsyncRuntimeState - Public runtime snapshot containing mode and background_worker.

Explanation ​

Detailed rules explaining key parameters and behaviors

  • This is a type alias, not a live runtime controller.
  • The current fields are mode : AsyncRuntimeMode and background_worker : Bool.
  • async_runtime_state() returns this type directly as an environment-level snapshot.
  • async_runtime_state() currently builds that snapshot from async_runtime_mode() and async_runtime_supports_background_worker().
  • async_runtime_state_to_json(...) and stringify_async_runtime_state(...) serialize the same snapshot shape for diagnostics.
  • AsyncRuntimeState::new(...) can also construct this type manually, but manual construction is synthetic data and does not probe the current backend by itself.
  • The type itself does not distinguish live backend snapshots from hand-built ones; callers must track whether a given AsyncRuntimeState value came from async_runtime_state() or from manual construction.

How to Use ​

Here are some specific examples provided.

When Need A Typed Backend Capability Snapshot ​

When startup or diagnostics code should keep the runtime state as structured data:

moonbit
let runtime : AsyncRuntimeState = async_runtime_state()

In this example, the backend capability snapshot stays available as a typed value instead of only as printed text.

When Need To Read Runtime Mode And Worker Support Together ​

When code should inspect both async mode and worker availability from one object:

moonbit
let runtime = async_runtime_state()
if runtime.background_worker {
  println(async_runtime_mode_label(runtime.mode))
}

In this example, both fields are consumed from the same public snapshot type.

Error Case ​

e.g.:

  • AsyncRuntimeState itself does not have a runtime failure mode.

  • The snapshot is point-in-time diagnostic data; it should not be treated as proof that every target was re-verified in the current release cycle.

  • Because this is just a data shape, manual construction can represent combinations that do not come from the current backend probe.

  • Receiving an AsyncRuntimeState value alone does not prove it came from the current backend rather than from a synthetic constructor path.

Notes ​

  1. Use async_runtime_state() when you need a value of this type from the current backend.

  2. Use AsyncLoggerState when logger-instance queue and lifecycle information is also required.

  3. Use async_runtime_mode_label(...) when the mode field should be rendered as stable text such as native_worker or compatibility.

Published from the repository docs folder with VitePress.