From bf7512d1130a375df4fd44ab0001d62975e785be Mon Sep 17 00:00:00 2001 From: Nanaloveyuki Date: Sat, 13 Jun 2026 22:56:51 +0800 Subject: [PATCH] :memo: document runtime sink auto flush methods --- docs/api/index.md | 2 + docs/api/runtime-sink-file-auto-flush.md | 75 ++++++++++++++++++++ docs/api/runtime-sink-file-set-auto-flush.md | 75 ++++++++++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 docs/api/runtime-sink-file-auto-flush.md create mode 100644 docs/api/runtime-sink-file-set-auto-flush.md diff --git a/docs/api/index.md b/docs/api/index.md index b20fe21..2667640 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -361,6 +361,8 @@ BitLogger API navigation. - [runtime-sink-close.md](./runtime-sink-close.md) - [runtime-sink-pending-count.md](./runtime-sink-pending-count.md) - [runtime-sink-dropped-count.md](./runtime-sink-dropped-count.md) +- [runtime-sink-file-auto-flush.md](./runtime-sink-file-auto-flush.md) +- [runtime-sink-file-set-auto-flush.md](./runtime-sink-file-set-auto-flush.md) - [configured-logger.md](./configured-logger.md) - [configured-logger-flush.md](./configured-logger-flush.md) - [configured-logger-drain.md](./configured-logger-drain.md) diff --git a/docs/api/runtime-sink-file-auto-flush.md b/docs/api/runtime-sink-file-auto-flush.md new file mode 100644 index 0000000..694b2b8 --- /dev/null +++ b/docs/api/runtime-sink-file-auto-flush.md @@ -0,0 +1,75 @@ +--- +name: runtime-sink-file-auto-flush +group: api +category: runtime +update-time: 20260613 +description: Read whether the file-backed RuntimeSink currently has auto-flush enabled. +key-word: + - runtime + - sink + - file + - public +--- + +## Runtime-sink-file-auto-flush + +Read whether auto-flush is currently enabled on a file-backed `RuntimeSink`. This helper exposes one important direct runtime durability policy flag without going through `ConfiguredLogger`. + +### Interface + +```moonbit +pub fn RuntimeSink::file_auto_flush(self : RuntimeSink) -> Bool { +``` + +#### input + +- `self : RuntimeSink` - Runtime sink whose file auto-flush policy should be inspected. + +#### output + +- `Bool` - Whether auto-flush is currently enabled. + +### Explanation + +Detailed rules explaining key parameters and behaviors + +- Plain `File` runtime variants report the current auto-flush policy from the wrapped `FileSink`. +- `QueuedFile` runtime variants forward the policy from the wrapped inner `FileSink`. +- Non-file runtime variants return `false`. +- This helper exposes policy state only and does not force any flush action. + +### How to Use + +Here are some specific examples provided. + +#### When Need Direct Runtime Durability Visibility + +When code owns a `RuntimeSink` directly and should expose whether each file write auto-flushes: +```moonbit +let enabled = sink.file_auto_flush() +``` + +In this example, runtime file durability policy is surfaced without going through a logger wrapper. + +#### When Validate Direct Policy Updates + +When code should observe auto-flush after a direct runtime setter call: +```moonbit +ignore(sink.file_set_auto_flush(true)) +ignore(sink.file_auto_flush()) +``` + +In this example, callers verify the updated policy on the runtime sink itself. + +### Error Case + +e.g.: +- If the runtime sink is not file-backed, the method returns `false`. + +- If callers need to actually flush file output, `file_flush()` is the operational API. + +### Notes + +1. Use this helper to inspect direct runtime durability policy on `RuntimeSink` values. + +2. It complements `file_set_auto_flush(...)` rather than replacing real flush actions. diff --git a/docs/api/runtime-sink-file-set-auto-flush.md b/docs/api/runtime-sink-file-set-auto-flush.md new file mode 100644 index 0000000..81eab87 --- /dev/null +++ b/docs/api/runtime-sink-file-set-auto-flush.md @@ -0,0 +1,75 @@ +--- +name: runtime-sink-file-set-auto-flush +group: api +category: runtime +update-time: 20260613 +description: Update the auto-flush policy used by a file-backed RuntimeSink. +key-word: + - runtime + - sink + - file + - public +--- + +## Runtime-sink-file-set-auto-flush + +Update the auto-flush policy used by a file-backed `RuntimeSink`. This helper changes direct runtime durability behavior without rebuilding or rewrapping the sink. + +### Interface + +```moonbit +pub fn RuntimeSink::file_set_auto_flush(self : RuntimeSink, enabled : Bool) -> Bool { +``` + +#### input + +- `self : RuntimeSink` - Runtime sink whose file auto-flush policy should change. +- `enabled : Bool` - New auto-flush setting. + +#### output + +- `Bool` - Whether the policy update was applied. + +### Explanation + +Detailed rules explaining key parameters and behaviors + +- Plain `File` runtime variants update the wrapped `FileSink` auto-flush policy and return `true`. +- `QueuedFile` runtime variants forward the update to the wrapped inner `FileSink` and return `true`. +- Non-file runtime variants return `false`. +- This helper changes policy only; it does not itself flush pending data. + +### How to Use + +Here are some specific examples provided. + +#### When Need Direct Runtime Durability Tuning + +When a file-backed runtime sink should start flushing each write automatically: +```moonbit +ignore(sink.file_set_auto_flush(true)) +``` + +In this example, runtime durability policy is updated without rebuilding the sink. + +#### When Need To Relax Flush Pressure On A Runtime Sink + +When file writes should stop auto-flushing for throughput reasons: +```moonbit +let ok = sink.file_set_auto_flush(false) +``` + +In this example, the call site updates policy explicitly and can inspect the result. + +### Error Case + +e.g.: +- If the runtime sink is not file-backed, the method returns `false`. + +- If callers need an immediate flush action, `file_flush()` is the operational API. + +### Notes + +1. Use this helper for direct runtime durability tuning on `RuntimeSink` values. + +2. Pair it with `file_auto_flush()` to verify the active policy.