LocalStorageCheckpointer

class LocalStorageCheckpointer<State>(serializer: StateSerializer<State>, keyPrefix: String = "telar.checkpoint.", maxHistory: Int = 1) : Checkpointer<State>

A persistent Checkpointer for apps that run in a browser. It stores the checkpoints of each thread in the page's localStorage, so a paused run is still there after the page is reloaded or the browser is closed.

val config = GraphConfig(
threadId = "ticket-42",
checkpointer = LocalStorageCheckpointer(KotlinxStateSerializer<Ticket>()),
interruptBefore = setOf("pay"),
)

What to know about localStorage:

  • It belongs to the origin of the page (scheme, host and port). Every page of that origin reads and writes the same entries, so give keyPrefix a name of your own.

  • A browser keeps about 5 MB for an origin. When it is full, save throws a LocalStorageException and the checkpoints that were stored before stay as they were. For that reason a thread keeps only its latest checkpoint unless you raise maxHistory.

  • The person using the browser can read and change it. Do not keep secrets in the state.

  • It is not available in a web worker, on Node.js, or when the browser blocks storage for the page. Every call then throws a LocalStorageException.

The entries have the format of CheckpointCodec, the same as the files of FileCheckpointer.

Parameters

serializer

converts the graph state to and from a string.

keyPrefix

what the key of an entry starts with. The thread id follows it.

maxHistory

how many checkpoints a thread keeps, counted from the latest, for CompiledGraph.history and fork. The default keeps only the latest.

Throws

Constructors

Link copied to clipboard
constructor(serializer: StateSerializer<State>, keyPrefix: String = "telar.checkpoint.", maxHistory: Int = 1)

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>)