Files
BitLogger/docs/api/async-runtime-mode.md
T
2026-05-12 13:20:36 +08:00

2.3 KiB

name, group, category, update-time, description, key-word
name group category update-time description key-word
async-runtime-mode api async 20260512 Read the current async runtime mode and distinguish native worker behavior from compatibility behavior.
async
runtime
mode
public

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 - Either NativeWorker or Compatibility.

Explanation

Detailed rules explaining key parameters and behaviors

  • The return value is determined by the active backend implementation.
  • 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.
  • This API is intentionally small and useful for lightweight branching.

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 you need worker support as a direct boolean, use async_runtime_supports_background_worker() instead.

Notes

Notes are here.

  1. Use this API for minimal mode branching.

  2. Use async_runtime_state() when you also want worker support packaged into one object.

  3. Use AsyncLogger::state() when you need logger instance counters and lifecycle flags too.

  4. The enum is intentionally small to keep capability branching simple.