📝 补充runtime文档

This commit is contained in:
Nanaloveyuki
2026-07-07 11:25:02 +08:00
parent 3bac025acf
commit 7946dcdaee
31 changed files with 664 additions and 367 deletions
+23 -15
View File
@@ -2,8 +2,8 @@
name: runtime-sink-flush
group: api
category: runtime
update-time: 20260613
description: Flush a RuntimeSink and return how many queued or file-backed operations were advanced.
update-time: 20260707
description: Compatibility RuntimeSink flush helper that still returns one Int by collapsing generic queue progress and plain-file fallback steps.
key-word:
- runtime
- sink
@@ -13,7 +13,7 @@ key-word:
## Runtime-sink-flush
Flush a `RuntimeSink` and return how much work was advanced. This is the direct runtime control API behind configured logger flush behavior.
Flush a `RuntimeSink` and return one compatibility count. This helper is still available for older code, but new generic runtime code should prefer `flush_progress()` because it exposes queue advancement and plain-file fallback steps separately.
### Interface
@@ -27,16 +27,18 @@ pub fn RuntimeSink::flush(self : RuntimeSink) -> Int {
#### output
- `Int` - Count of advanced operations as reported by the concrete runtime sink variant.
- `Int` - Compatibility count produced from the structured `flush_progress()` result.
### Explanation
Detailed rules explaining key parameters and behaviors
- Plain console-style runtime sinks return `0` because they do not keep explicit buffered flush state here.
- Plain file runtime sinks call `FileSink::flush()` and convert the boolean result into `1` or `0`.
- Queue-wrapped runtime sinks forward to the wrapped queue sink's `flush()` behavior.
- This method is the direct sink-level API used by `ConfiguredLogger::flush(...)`.
- This method now delegates to `flush_progress()` and sums `queue_advanced_count + file_flush_step_count` back into one compatibility number.
- Plain console-style runtime sinks still return `0` because the structured result stays zeroed.
- Plain file runtime sinks still expose their generic fallback through `1` or `0`, but that value now comes from `file_flush_step_count` in the structured result.
- Queue-wrapped runtime sinks still return the number of queued records consumed during that flush.
- For queued file sinks, a positive returned count still means queue advancement, not a durable file-write count.
- This method remains the direct sink-level API used by `ConfiguredLogger::flush(...)`.
### How to Use
@@ -44,33 +46,39 @@ Here are some specific examples provided.
#### When Need Direct Runtime Flush Control
When code is working with a `RuntimeSink` value directly instead of going through `ConfiguredLogger`:
When older code is already built around one numeric flush count:
```moonbit
let flushed = sink.flush()
```
In this example, the runtime sink reports how much flush work was advanced.
In this example, the runtime sink still reports one compatibility count.
#### When Need Queue Or File Progress Visibility
When support code should observe whether a direct flush request did useful work:
When code only needs a coarse non-zero check and does not care which runtime dimension advanced:
```moonbit
if sink.flush() > 0 {
()
}
```
In this example, the return value reflects whether queue draining or file flushing advanced any work.
In this example, the count still reflects generic runtime advancement, not durable file success.
### Error Case
e.g.:
- If the runtime sink shape has no flushable state, the method may simply return `0`.
- If callers need bounded queue progress, `drain(...)` is the better API.
- If callers need truthful generic progress semantics, `flush_progress()` is the better API.
- If callers need bounded queue progress, `drain_progress(...)` is usually the better API.
- If callers need file-specific success semantics on a file-backed sink, `file_flush()` is the better API.
### Notes
1. Use this helper when direct runtime sink flushing matters.
1. Treat this method as a compatibility helper for older numeric code.
2. `ConfiguredLogger::flush(...)` is the higher-level wrapper for config-built loggers.
2. Prefer `flush_progress()` in new generic runtime code.
3. `ConfiguredLogger::flush(...)` is the higher-level wrapper for config-built loggers.