live

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package live holds the Directory the service is serving: the document, its Trash and the Editor's settings as last saved, the tree derived from them, and the one step Undo can return to.

It is the only place those change. A write is a function from the current Snapshot to the next store.State; a Copy serialises writes, saves each through its Writer, and swaps the result in only once that succeeds, so a failed save leaves the served Directory matching the disk. Readers take a Snapshot and hold no lock: nothing a Snapshot points at is ever mutated, only replaced.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnbuildable = errors.New("document does not build a tree")

ErrUnbuildable means a document's Households do not form a tree, so it cannot be served. A Copy never writes such a document.

Functions

This section is empty.

Types

type Clock

type Clock func() time.Time

Clock reports the current time. The Trash's 30 days are measured against it.

type Copy

type Copy struct {
	// contains filtered or unexported fields
}

Copy is the Directory being served. Build one with New.

func New

func New(initial store.State, w Writer, now Clock) (*Copy, error)

New serves initial. A missing Trash is an empty one and missing settings are an untitled Directory, as they are for a missing file.

func (*Copy) Snapshot

func (c *Copy) Snapshot() Snapshot

Snapshot is what is served now. It takes no lock.

func (*Copy) Undo

func (c *Copy) Undo(token string) (Snapshot, bool, error)

Undo returns to the state before the latest save, if token names that save. A token that is empty, was never issued, or was retired by a newer save is not an error: Undo reports false and changes nothing.

Undo is exact — it does not purge the Trash it restores — and it is one step: afterwards there is nothing to undo, so Undo is never a toggle. It returns the Snapshot it leaves served, so a caller checking what still exists sees the state the Undo produced rather than a later one.

func (*Copy) Update

func (c *Copy) Update(build func(Snapshot) (store.State, error)) (Saved, error)

Update makes one change. build receives the current Snapshot and returns the next State; it runs while other writers wait, so it must do no I/O and must not call back into c.

A field build leaves nil is left as served, and handing back the Snapshot's effective Trash means the Trash did not change. When nothing changed, Update writes nothing, issues no Undo and leaves the previous Undo standing. Otherwise it purges the Trash if the Trash changed, builds the tree, writes, and only then serves the result and records it as the one step Undo can reverse.

An error from build is returned as it is, so a caller can carry its own refusal out; nothing is written. Any error leaves the served state and its Undo untouched.

type Saved

type Saved struct {
	// Snapshot is what is served after the call, whether or not it saved.
	Snapshot Snapshot
	// Changed is false when the build handed back what was already served:
	// nothing was written and no Undo was issued.
	Changed bool
	// Undo is the token of this save's Undo, or empty when nothing changed.
	Undo string
}

Saved is what an Update did.

type Snapshot

type Snapshot struct {
	Document *store.Document
	Tree     *rolo.Tree
	// Trash is the Trash as the Editor should see it: purged as of Now. An
	// expired entry nothing needs is still stored — and restorable — until
	// the next Trash write, but it must not be listed or counted. Reading it
	// writes nothing.
	Trash    *store.Trash
	Settings *store.Settings
	// Now is the one clock reading this Snapshot was taken at. A write uses
	// it for everything it dates, so a deletion and the purge beside it agree.
	Now time.Time
	// contains filtered or unexported fields
}

Snapshot is the served Directory at one moment. Nothing it points at is ever mutated; a write that wants to change something builds a new value.

func (Snapshot) CanUndo

func (s Snapshot) CanUndo(token string) bool

CanUndo reports whether token names the latest save, so that an Undo offered with it would still work.

func (Snapshot) State

func (s Snapshot) State() store.State

State is the served state as stored, with the Trash unpurged. It is the base every write builds its next State from.

type Writer

type Writer interface {
	Write(prev, next store.State) error
}

Writer persists a change. It is handed the state being replaced as well as the new one, so it can tell which files changed and order the writes so that a crash cannot lose a Household (store.Persist, ADR-0012). store.Paths satisfies it.

It is called synchronously, inside the request that made the change: the atomic write in internal/store protects a write that has begun, and graceful shutdown waits for in-flight requests, so a write handed to a goroutine would escape both.

type WriterFunc

type WriterFunc func(prev, next store.State) error

WriterFunc adapts a function to Writer.

func (WriterFunc) Write

func (f WriterFunc) Write(prev, next store.State) error

Write calls f.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL