📝 clarify async state snapshot docs

This commit is contained in:
Nanaloveyuki
2026-06-14 07:04:55 +08:00
parent 6c5f4aaa0e
commit a2b37dfe53
3 changed files with 13 additions and 4 deletions
+6
View File
@@ -40,6 +40,8 @@ Detailed rules explaining key parameters and behaviors
- `runtime` embeds the result of `async_runtime_state()` so callers do not need to join separate helpers manually.
- Because the snapshot is assembled field by field when `state()` is called, later logger changes require calling `state()` again rather than reusing an older `AsyncLoggerState` value as if it refreshed itself.
- That field-by-field assembly also means this helper is not an atomic freeze across all refs; under concurrent logger activity, neighboring fields can reflect slightly different instants.
- After a worker failure, `has_failed=true`, a non-empty `last_error`, and `pending_count>0` can legitimately appear together in one snapshot until later cleanup or a later started `run()` changes them.
- `state()` only reports the current field values; it does not clear failure state, drain backlog, or synchronize pending work by itself.
### How to Use
@@ -69,6 +71,8 @@ if state.has_failed {
In this example, the same snapshot object works for conditional diagnostics and serialization.
And the reported failure fields can still appear together with non-zero backlog when a worker stopped early.
### Error Case
e.g.:
@@ -80,6 +84,8 @@ e.g.:
- If concurrent logger activity is still changing counters or flags while `state()` runs, the returned value is still useful for diagnostics but should not be treated as a transactional snapshot.
- A snapshot showing `has_failed=true` does not imply `pending_count` is already `0`; remaining queued records may still be visible until later cleanup or restart.
### Notes
1. Prefer this API over manually combining `pending_count()`, `dropped_count()`, and runtime-mode helpers.