valuesink

package
v0.0.0-...-2e8e066 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2019 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClosed is returned from calls to a service or interface in the event
	// that the Close() function has already been called.
	ErrClosed = errors.New("value sink is closing or already closed")
)

Functions

This section is empty.

Types

type Sink

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

Sink represents a threadsafe value container that can receive updates. It is intended to be used in conjuction with an external trigger or polling function that updates the contained value.

Sink always stores the last non-nil value provided via update for which there was no associated error. This value can be retrieved by calling the value function.

It is safe to intialize a sink with its zero value or to embed a sink in other types.

func (*Sink) Close

func (s *Sink) Close()

Close releases any resources consumed by the sink.

func (*Sink) Ready

func (s *Sink) Ready() (ready bool)

Ready returns true if the sink contains a value, otherwise it returns false.

func (*Sink) Update

func (s *Sink) Update(value interface{}, timestamp time.Time, err error)

Update will update the value contained in the sink and unblock any oustanding calls to WaitReady.

func (*Sink) Value

func (s *Sink) Value() (value interface{}, timestamp time.Time, err error)

Value returns the current value if the sink is not empty, otherwise it returns nil.

Calls to this function are guaranteed to succeed if the sink is ready, as indicated by Sink.Ready().

func (*Sink) WaitReady

func (s *Sink) WaitReady() (err error)

WaitReady blocks until the next call to Update if the sink isn't ready, otherwise WaitReady does nothing and does not block.

WaitReady returns nil when the sink is ready with a value. If a call to Update provides an error, WaitReady unblocks and returns that error.

If the sink does not contain a value and has been closed then ErrClosed will be returned.

Jump to

Keyboard shortcuts

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