📝 consolidate logger API and async lifecycle guidance

This commit is contained in:
Nanaloveyuki
2026-06-14 14:00:00 +08:00
parent 4f2ad097af
commit 265cd69ea9
154 changed files with 2419 additions and 396 deletions
+13 -2
View File
@@ -2,8 +2,8 @@
name: async-runtime-mode-label
group: api
category: async
update-time: 20260512
description: Convert AsyncRuntimeMode into a stable string label for logs, JSON, and diagnostics.
update-time: 20260614
description: Convert AsyncRuntimeMode into its canonical stable string label for logs, JSON, and diagnostics.
key-word:
- async
- runtime
@@ -36,7 +36,10 @@ Detailed rules explaining key parameters and behaviors
- The returned value is intended for diagnostics and stable output, not just debugging prints.
- It keeps mode serialization logic in one place.
- This helper is used by async runtime JSON helpers.
- `async_runtime_state_to_json(...)` serializes the `mode` field through this helper, so runtime snapshots and direct label rendering share the same canonical text.
- Labels are more stable for telemetry and docs than ad hoc manual matching at call sites.
- The current canonical labels are exactly `native_worker` for `NativeWorker` and `compatibility` for `Compatibility`.
- This helper is only a pure enum-to-string mapping. It does not inspect the active backend or verify that the supplied enum still matches the current runtime environment.
### How to Use
@@ -65,5 +68,13 @@ In this example, code gets a stable string without duplicating enum matching log
e.g.:
- This API assumes a valid `AsyncRuntimeMode` input and does not expose a normal runtime error path.
- If callers need the current backend-derived mode rather than a previously stored enum value, they must call `async_runtime_mode()` first and then label that result.
- If callers need the whole runtime object rather than a string label, use `async_runtime_state()`.
### Notes
1. Use this helper when mode values should be rendered as stable text instead of manual enum matching.
2. `async_runtime_state_to_json(...)` uses these exact labels when serializing runtime snapshots.