Skip to contents

What keeps logs for others to read, by the rules every store keeps (contract/streaming.md, "The rules a store keeps"). memory_store() keeps them in this R session. A store of your own is a list (or an environment) of three functions:

Usage

memory_store(name = "memory")

store_refuse(code, message = "", event = NULL)

Arguments

name

A name, for messages.

code

The refusal's code: "event-malformed", "event-conflict", "event-gap", "event-after-end", "event-start" or "event-unknown".

message

Why, in words.

event

The position of the event refused, list(writer, seq).

Value

A store.

Details

  • append(events): append one event, or a list of events as one step (kept whole or not at all). Returns "kept" or "duplicate", or raises the contract's refusal with store_refuse(). Any other error is "no answer": the append may have been kept, and the writer sends it again.

  • claim(tree): a later writer claims an unfinished log: list(writer, after).

  • read(tree, after = NULL): the kept events after a position (all of them after NULL); refuses event-unknown when it has no such event.

Every event is checked against the contract's event schema first.

Examples

store <- memory_store()
# with_ai_config(team(message), journal = ai_journal(store, required = TRUE))