Documentation
¶
Overview ¶
Package persistence defines where the state of shared documents is stored, keyed by room name as in ygo's persistence package. A store holds the head state of each room, which is the full text of the document. There is no history: storing replaces what was stored before.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrRoomNotFound = errors.New("persistence: room not found")
ErrRoomNotFound is returned (wrapped) by Load when nothing was stored for the room yet. Test for it with errors.Is.
Functions ¶
func WriteAtomic ¶
WriteAtomic replaces path through a temporary file in the same directory, so other processes never see a half-written file.
Types ¶
type FilePersistence ¶
type FilePersistence struct {
// contains filtered or unexported fields
}
FilePersistence keeps the state of a room in the file dir/room, so that other programs can read and edit it. It implements Watcher.
func NewFilePersistence ¶
func NewFilePersistence(dir string) (*FilePersistence, error)
NewFilePersistence opens (creating if necessary) a store in the directory dir.
type MemoryPersistence ¶
type MemoryPersistence struct {
// contains filtered or unexported fields
}
MemoryPersistence keeps the state of rooms in memory. It is safe for concurrent use.
func NewMemoryPersistence ¶
func NewMemoryPersistence() *MemoryPersistence
type Persistence ¶
type Persistence interface {
// Load returns the stored state of room, or an error wrapping
// ErrRoomNotFound if there is none.
Load(ctx context.Context, room string) ([]byte, error)
// Store replaces the state of room.
Store(ctx context.Context, room string, state []byte) error
}
Persistence stores the head state of rooms.
type Watcher ¶
type Watcher interface {
// Watch sends a value whenever the state of room may have changed. The
// channel is closed when ctx is done. Sends never block: values are
// dropped while one is already pending.
Watch(ctx context.Context, room string) (<-chan struct{}, error)
}
Watcher is implemented by stores that can tell when the state of a room was changed by someone else. Consumers that find it on a store use it to react sooner than polling would.