Documentation ¶
Index ¶
- Variables
- func IsEOS(err error) bool
- func NewBroadcast() (Sink, Broadcast)
- func NewPipe(opts ...PipeOpt) (Source, Sink)
- func Pump(ctx context.Context, dst Sink, src Source) error
- type Broadcast
- type EOS
- type ErrorCloser
- type FuncSink
- type FuncSource
- type Observable
- type PipeOpt
- type PushSource
- type Sink
- type SliceSink
- type SliceSource
- type Source
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrPourToClosedSink = errors.New("pour to closed sink")
Functions ¶
func NewBroadcast ¶
NewBroadcast returns the Sink, to write to the broadcaster, and the new broadcast instance.
Types ¶
type Broadcast ¶
type Broadcast interface { // Register a Sink for updates to be sent. Register(dst Sink) func() }
Broadcast is an interface for registering one or more Sinks to recieve updates.
Example ¶
sink, bcast := NewBroadcast() defer sink.Close() var printOutput FuncSink = func( _ context.Context, v interface{}, _ error, ) error { if v == nil { return nil } fmt.Println(*v.(*string)) return nil } closeSink := bcast.Register(printOutput) defer closeSink() closeSink = bcast.Register(printOutput) defer closeSink() msg := "I sink this should be printed twice" _ = sink.Pour(context.Background(), &msg)
Output: I sink this should be printed twice I sink this should be printed twice
type EOS ¶
type EOS struct{}
EOS stands for End Of Stream. It signals when a non-blocking stream is empty, or a stream is closed.
Similar the io package's EOF.
type ErrorCloser ¶
type FuncSink ¶
FuncSink defines a function which can be used as a Sink.
func (FuncSink) CloseWithError ¶
type FuncSource ¶
FuncSource defines a function which can be used as a Source.
type Observable ¶
type Observable interface { // Broadcast allows subscribing to changes Broadcast // Set sets a new value Set(interface{}) error // Value returns the current value Value() (interface{}, error) }
Observabe wraps an interface{} value and allows tracking changes to it
func NewObservable ¶
func NewObservable(v interface{}) Observable
NewObservable returns a new Observable
type PipeOpt ¶
type PipeOpt func(*pipeOpts) error
PipeOpt configures NewPipes behavior
func NonBlocking ¶
func NonBlocking() PipeOpt
NonBlocking changes the behavior to assume a non-blocking backing medium
func WithBuffer ¶
WithBuffer sets the buffer size of the internal channel
type PushSource ¶
PushSource is the interface for requesting all content be written to the given sink.
type SliceSink ¶
type SliceSink struct {
// contains filtered or unexported fields
}
SliceSink binds Sink methods to an interface array.
func NewSliceSink ¶
func NewSliceSink(arg *[]interface{}) *SliceSink
NewSliceSink returns a new SliceSink bound to the given interface array.
type SliceSource ¶
type SliceSource []interface{}
SliceSink binds Source methods to an interface array.