luigi: go.cryptoscope.co/luigi Index | Examples | Files | Directories

package luigi

import "go.cryptoscope.co/luigi"

Index

Examples

Package Files

broadcast.go chan.go func.go obv.go slice.go stream.go

Variables

var ErrPourToClosedSink = errors.New("pour to closed sink")

func IsEOS Uses

func IsEOS(err error) bool

IsEOS checks whether the error is due to a closed stream.

func NewBroadcast Uses

func NewBroadcast() (Sink, Broadcast)

NewBroadcast returns the Sink, to write to the broadcaster, and the new broadcast instance.

func NewPipe Uses

func NewPipe(opts ...PipeOpt) (Source, Sink)

NewPipe returns both ends of a stream.

func Pump Uses

func Pump(ctx context.Context, dst Sink, src Source) error

Pump moves values from a source into a sink.

Currently this doesn't work atomically, so if a Sink errors in the Pour call, the value that was read from the source is lost.

type Broadcast Uses

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.

Code:

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 Uses

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.

func (EOS) Error Uses

func (_ EOS) Error() string

type ErrorCloser Uses

type ErrorCloser interface {
    CloseWithError(error) error
}

type FuncSink Uses

type FuncSink func(ctx context.Context, v interface{}, err error) error

FuncSink defines a function which can be used as a Sink.

func (FuncSink) Close Uses

func (fSink FuncSink) Close() error

Close implements the Sink interface.

func (FuncSink) CloseWithError Uses

func (fSink FuncSink) CloseWithError(err error) error

func (FuncSink) Pour Uses

func (fSink FuncSink) Pour(ctx context.Context, v interface{}) error

Pour implements the Sink interface.

type FuncSource Uses

type FuncSource func(context.Context) (interface{}, error)

FuncSource defines a function which can be used as a Source.

func (FuncSource) Next Uses

func (fSink FuncSource) Next(ctx context.Context) (interface{}, error)

Next implements the Pour interface.

type Observable Uses

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 Uses

func NewObservable(v interface{}) Observable

NewObservable returns a new Observable

type PipeOpt Uses

type PipeOpt func(*pipeOpts) error

PipeOpt configures NewPipes behavior

func NonBlocking Uses

func NonBlocking() PipeOpt

NonBlocking changes the behavior to assume a non-blocking backing medium

func WithBuffer Uses

func WithBuffer(bufSize int) PipeOpt

WithBuffer sets the buffer size of the internal channel

type PushSource Uses

type PushSource interface {
    Push(ctx context.Context, dst Sink) error
}

PushSource is the interface for requesting all content be written to the given sink.

type Sink Uses

type Sink interface {
    Pour(ctx context.Context, v interface{}) error
    Close() error
}

Sink is the interface which wraps methods writing to a stream.

type SliceSink Uses

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

SliceSink binds Sink methods to an interface array.

func NewSliceSink Uses

func NewSliceSink(arg *[]interface{}) *SliceSink

NewSliceSink returns a new SliceSink bound to the given interface array.

func (*SliceSink) Close Uses

func (sink *SliceSink) Close() error

Close is a dummy method to implement the Sink interface.

func (*SliceSink) Pour Uses

func (sink *SliceSink) Pour(ctx context.Context, v interface{}) error

Pour implements the Sink interface. It writes value to a destination Sink.

type SliceSource Uses

type SliceSource []interface{}

SliceSink binds Source methods to an interface array.

func (*SliceSource) Next Uses

func (src *SliceSource) Next(context.Context) (v interface{}, err error)

Next implements the Source interface.

type Source Uses

type Source interface {
    Next(context.Context) (obj interface{}, err error)
}

Source is the interface which wraps the Next method for reading from a stream.

Directories

PathSynopsis
json
lexpvar
mfr

Package luigi imports 5 packages (graph) and is imported by 81 packages. Updated 2020-01-31. Refresh now. Tools for package owners.