value

package
v0.0.0-...-cb77e8e Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package value provides atomic values with update notifications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorValue

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

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

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

Get returns the currently stored value or error.

func (*ErrorValue) Next

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

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

func (*ErrorValue) Set

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

Set updates the stored value and clears any error.

func (*ErrorValue) SetOrError

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

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

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

Value provides atomic value storage with update notifications.

func (*Value) Get

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

Get returns the currently stored value.

func (*Value) Next

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

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

Set updates the stored values and notifies any subscribers.

func (*Value) Subscribe

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.

Jump to

Keyboard shortcuts

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