FileStore

class FileStore(file: Path, scheduler: AsyncScheduler, logger: Logger, debounceSeconds: Long = 5)(source)

One persisted file, written whole and written atomically.

Durability lives here rather than at each write site: a file added later is written atomically because it is a FileStore, not because its author remembered to reach for the right helper.

Each store also owns its own DebouncedSaver rather than accepting one, because a saver drops a request while a write is pending and so serves exactly one file. That rule used to hold only because the wiring happened to construct a separate saver per file.

Decoding is left to the caller: the stores differ in what an unreadable file means - channels fail loudly, settings fall back to empty - and that is a policy the file cannot know.

Constructors

Link copied to clipboard
constructor(file: Path, scheduler: AsyncScheduler, logger: Logger, debounceSeconds: Long = 5)

Properties

Link copied to clipboard

The file's name, for log messages that tell the operator which file went wrong.

Functions

Link copied to clipboard
fun queueWrite(contents: () -> String)

Queues a debounced asynchronous write.

Link copied to clipboard
fun read(): String?

Reads the file, or returns null when it is not there yet.

Link copied to clipboard
fun write(contents: String)

Replaces the file with contents so nothing ever reads a half-written file.