atom

package
v0.0.0-...-1fa5987 Latest Latest
Warning

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

Go to latest
Published: May 14, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CodecJSON = &jsonCodec{}
View Source
var CodecString = &stringCodec{}

Functions

This section is empty.

Types

type Atom

type Atom interface {
	// Sets v to the current value in the atom.
	Deref(v any) error
	// Sets the current value in the atom to v.
	Reset(v any) error
	// Runs f in a compare-and-set loop until a write succeeds uncontended.
	// On each iterate of the loop, v is set to the current value in the atom.
	// If no error occurs, the successfully written value remains in v.
	Swap(v any, f func() error) error
}

Atom are uncoordinated, atomic reference cells. Inspired by <https://clojure.org/reference/atoms>.

type Codec

type Codec interface {
	Marshal(v any) ([]byte, error)
	Unmarshal(bs []byte, v any) error
}

type FileAtom

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

A atom durable on the local file system.

func NewFileAtom

func NewFileAtom(filename string, codec Codec) *FileAtom

func (*FileAtom) Deref

func (a *FileAtom) Deref(v any) error

func (*FileAtom) Reset

func (a *FileAtom) Reset(v any) error

func (*FileAtom) Swap

func (a *FileAtom) Swap(v any, f func() error) error

Jump to

Keyboard shortcuts

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