barista.run: barista.run/base/value Index | Files

package value

import "barista.run/base/value"

Package value provides atomic values with update notifications.

Index

Package Files

value.go

type ErrorValue Uses

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

ErrorValue adds an error to Value, allowing storage of either a value (interface{}) or an error.

func (*ErrorValue) Error Uses

func (e *ErrorValue) Error(err error) bool

Error replaces the stored value and returns true if non-nil, and simply returns false if nil.

func (*ErrorValue) Get Uses

func (e *ErrorValue) Get() (interface{}, error)

Get returns the currently stored value or error.

func (*ErrorValue) Next Uses

func (e *ErrorValue) Next() <-chan struct{}

Next returns a channel that will be closed on the next update, value or error.

func (*ErrorValue) Set Uses

func (e *ErrorValue) Set(value interface{})

Set updates the stored value and clears any error.

func (*ErrorValue) SetOrError Uses

func (e *ErrorValue) SetOrError(val interface{}, err error) bool

SetOrError combines Set and Error. It sets the error value and returns true if err is non-nil, otherwise it clears the error and sets the given value.

func (*ErrorValue) Subscribe Uses

func (e *ErrorValue) Subscribe() (sub <-chan struct{}, done func())

Subscribe returns a channel that will receive an empty struct{} on each value change (including errors), until it's cleaned up using the done func.

type Value Uses

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

Value provides atomic value storage with update notifications.

func (*Value) Get Uses

func (v *Value) Get() interface{}

Get returns the currently stored value.

func (*Value) Next Uses

func (v *Value) Next() <-chan struct{}

Next returns a channel that will be closed on the next update. Useful in a select, or as <-Next() to wait for value changes.

func (*Value) Set Uses

func (v *Value) Set(value interface{})

Set updates the stored values and notifies any subscribers.

func (*Value) Subscribe Uses

func (v *Value) Subscribe() (sub <-chan struct{}, done func())

Subscribe returns a channel that will receive an empty struct{} on each value change until it's cleaned up using the done func.

Package value imports 4 packages (graph) and is imported by 39 packages. Updated 2018-11-25. Refresh now. Tools for package owners.