mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-05-30 15:42:25 +00:00
77 lines
2.0 KiB
Markdown
77 lines
2.0 KiB
Markdown
---
|
|
name: async-logger-is-running
|
|
group: api
|
|
category: async
|
|
update-time: 20260512
|
|
description: Read whether the async logger worker is currently running and draining the queue.
|
|
key-word:
|
|
- async
|
|
- logger
|
|
- lifecycle
|
|
- public
|
|
---
|
|
|
|
## Async-logger-is-running
|
|
|
|
Read whether the async logger worker is currently active. This helper is useful for runtime diagnostics and shutdown coordination.
|
|
|
|
### Interface
|
|
|
|
```moonbit
|
|
pub fn[S] AsyncLogger::is_running(self : AsyncLogger[S]) -> Bool {}
|
|
```
|
|
|
|
#### input
|
|
|
|
- `self : AsyncLogger[S]` - Async logger whose worker state should be inspected.
|
|
|
|
#### output
|
|
|
|
- `Bool` - Whether the async worker loop is currently running.
|
|
|
|
### Explanation
|
|
|
|
Detailed rules explaining key parameters and behaviors
|
|
|
|
- `run()` sets the running state while the worker loop is active.
|
|
- The flag is cleared when the worker exits normally or after failure handling finishes.
|
|
- A logger may be closed while still running briefly during final drain or shutdown processing.
|
|
- This helper focuses on worker activity rather than queue size or failure details.
|
|
|
|
### How to Use
|
|
|
|
Here are some specific examples provided.
|
|
|
|
#### When Need Worker Activity Diagnostics
|
|
|
|
When runtime output should show whether the worker loop is active:
|
|
```moonbit
|
|
println(logger.is_running().to_string())
|
|
```
|
|
|
|
In this example, diagnostics can distinguish an idle configured logger from one with an active worker.
|
|
|
|
#### When Coordinate Shutdown Waiting
|
|
|
|
When code should poll worker completion explicitly:
|
|
```moonbit
|
|
while logger.is_running() {
|
|
@async.pause()
|
|
}
|
|
```
|
|
|
|
In this example, callers watch the worker lifecycle directly.
|
|
|
|
### Error Case
|
|
|
|
e.g.:
|
|
- If `is_running()` is `false`, pending records may still exist if the worker was never started or has already failed.
|
|
|
|
- If callers need a one-shot lifecycle flow, `shutdown()` is usually better than manual polling.
|
|
|
|
### Notes
|
|
|
|
1. Use this helper for worker activity checks, not as a complete health signal.
|
|
|
|
2. Pair it with `has_failed()` or `state()` when diagnosing stalled pipelines.
|