safe

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ref

type Ref[T any] struct {
	// contains filtered or unexported fields
}

Ref is a generic struct that holds concurrent read and write objects to allow for safe concurrent read access with minimal locking, and atomic updates to the write object.

func NewRef

func NewRef[T any](t *T) *Ref[T]

NewRef creates a new Ref instance with an initial value that is a pointer.

func (*Ref[T]) Load

func (rw *Ref[T]) Load() *T

Load returns the current object.

func (*Ref[T]) MarshalJSON

func (rw *Ref[T]) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the read object.

func (*Ref[T]) Read

func (rw *Ref[T]) Read() *T

Read returns a copy of the object.

func (*Ref[T]) Replace

func (rw *Ref[T]) Replace(new *T) (old *T)

Replace replaces the ref and returns the old ref

func (*Ref[T]) UnmarshalJSON

func (rw *Ref[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the JSON data and updates the write object.

Jump to

Keyboard shortcuts

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