FileCheckpointer

class FileCheckpointer<State>(directory: Path, serializer: StateSerializer<State>, fileSystem: FileSystem = SystemFileSystem, maxHistory: Int = Int.MAX_VALUE) : Checkpointer<State>

A persistent Checkpointer that stores the checkpoints of each thread in one file inside directory: one line of JSON for each step of the thread, oldest first.

Works on every target that has a file system: JVM/Android, Apple, Linux and Windows native, and JS/Wasm running on Node.js. It is not available in browsers.

Writes are atomic: a checkpoint is written to a temporary file and then moved into place, so a crash in the middle of a save leaves the previous checkpoints intact. One instance is safe to share between coroutines; do not point several instances or processes at the same directory.

A save writes the file of its thread again, with the whole history. Give a thread that runs for hundreds of steps a maxHistory.

Parameters

directory

where checkpoint files are stored. Created if it does not exist.

serializer

converts the graph state to and from a string.

fileSystem

the file system to use; replaceable in tests.

maxHistory

how many checkpoints a thread keeps, counted from the latest. The default keeps all of them; 1 keeps only the latest.

Throws

Constructors

Link copied to clipboard
constructor(directory: Path, serializer: StateSerializer<State>, fileSystem: FileSystem = SystemFileSystem, maxHistory: Int = Int.MAX_VALUE)

Functions

Link copied to clipboard
open suspend override fun delete(threadId: String)
Link copied to clipboard
open suspend override fun history(threadId: String): List<Checkpoint<State>>
Link copied to clipboard
open suspend override fun load(threadId: String): Checkpoint<State>?
Link copied to clipboard
open suspend override fun save(threadId: String, checkpoint: Checkpoint<State>)