shadow

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2017 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("shadow closed")

ErrClosed is returned by any closed values.

A "closed value" is when the shadow has been notified that the real side is complete and any blocking values will _never_ be satisfied in the future. In this case, this error is returned. If a value is already available, that is still returned.

Functions

func Close added in v0.7.11

func Close(v interface{}) error

Close will close all shadow values within the given structure.

This uses reflection to walk the structure, find all shadow elements, and close them. Currently this will only find struct fields that are shadow values, and not slice elements, etc.

Types

type ComparedValue

type ComparedValue struct {
	// Func is a function that is given the lookup key and a single
	// stored value. If it matches, it returns true.
	Func func(k, v interface{}) bool
	// contains filtered or unexported fields
}

ComparedValue is a struct that finds a value by comparing some key to the list of stored values. This is useful when there is no easy uniquely identifying key that works in a map (for that, use KeyedValue).

ComparedValue is very expensive, relative to other Value types. Try to limit the number of values stored in a ComparedValue by potentially nesting it within a KeyedValue (a keyed value points to a compared value, for example).

func (*ComparedValue) Close

func (w *ComparedValue) Close() error

Close closes the value. This can never fail. For a definition of "close" see the ErrClosed docs.

func (*ComparedValue) SetValue

func (w *ComparedValue) SetValue(v interface{})

func (*ComparedValue) Value

func (w *ComparedValue) Value(k interface{}) interface{}

Value returns the value that was set for the given key, or blocks until one is available.

func (*ComparedValue) ValueOk

func (w *ComparedValue) ValueOk(k interface{}) (interface{}, bool)

ValueOk gets the value for the given key, returning immediately if the value doesn't exist. The second return argument is true if the value exists.

type KeyedValue

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

KeyedValue is a struct that coordinates a value by key. If a value is not available for a give key, it'll block until it is available.

func (*KeyedValue) Close

func (w *KeyedValue) Close() error

Close closes the value. This can never fail. For a definition of "close" see the ErrClosed docs.

func (*KeyedValue) Init

func (w *KeyedValue) Init(k string, v interface{})

Init will initialize the key to a given value only if the key has not been set before. This is safe to call multiple times and in parallel.

func (*KeyedValue) SetValue

func (w *KeyedValue) SetValue(k string, v interface{})

func (*KeyedValue) Value

func (w *KeyedValue) Value(k string) interface{}

Value returns the value that was set for the given key, or blocks until one is available.

func (*KeyedValue) ValueOk

func (w *KeyedValue) ValueOk(k string) (interface{}, bool)

ValueOk gets the value for the given key, returning immediately if the value doesn't exist. The second return argument is true if the value exists.

func (*KeyedValue) WaitForChange

func (w *KeyedValue) WaitForChange(k string) interface{}

WaitForChange waits for the value with the given key to be set again. If the key isn't set, it'll wait for an initial value. Note that while it is called "WaitForChange", the value isn't guaranteed to _change_; this will return when a SetValue is called for the given k.

type OrderedValue

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

OrderedValue is a struct that keeps track of a value in the order it is set. Each time Value() is called, it will return the most recent calls value then discard it.

This is unlike Value that returns the same value once it is set.

func (*OrderedValue) SetValue

func (w *OrderedValue) SetValue(v interface{})

SetValue sets the latest value.

func (*OrderedValue) Value

func (w *OrderedValue) Value() interface{}

Value returns the last value that was set, or blocks until one is received.

type Value

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

Value is a struct that coordinates a value between two parallel routines. It is similar to atomic.Value except that when Value is called if it isn't set it will wait for it.

The Value can be closed with Close, which will cause any future blocking operations to return immediately with ErrClosed.

func (*Value) Close

func (w *Value) Close() error

Close closes the value. This can never fail. For a definition of "close" see the struct docs.

func (*Value) Lock added in v0.10.0

func (v *Value) Lock()

func (*Value) SetValue

func (w *Value) SetValue(v interface{})

SetValue sets the value.

func (*Value) Unlock added in v0.10.0

func (v *Value) Unlock()

func (*Value) Value

func (w *Value) Value() interface{}

Value returns the value that was set.

Jump to

Keyboard shortcuts

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