events

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: Apache-2.0 Imports: 10 Imported by: 4

Documentation

Index

Constants

View Source
const DefaultPolling = time.Millisecond * time.Duration(200)

Variables

View Source
var (
	Error = New("error")
)

Functions

func NewEventStream added in v0.16.0

func NewEventStream(stream rpcc.Stream, decoder Decoder) events.Stream

Types

type Decoder added in v0.16.0

type Decoder func(ctx context.Context, stream rpcc.Stream) (core.Value, error)

type Event

type Event struct {
	ID   ID
	Data interface{}
}

Event represents a system event that is returned from an event source

type EventStream added in v0.16.0

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

func (*EventStream) Close added in v0.16.0

func (e *EventStream) Close(_ context.Context) error

func (*EventStream) Read added in v0.16.0

func (e *EventStream) Read(ctx context.Context) <-chan events.Message

type Factory added in v0.16.0

type Factory func(ctx context.Context) (rpcc.Stream, error)

type Function

type Function func(ctx context.Context) (core.Value, error)

type Handler added in v0.10.0

type Handler func(ctx context.Context, message interface{}) bool

Handler represents a function that is called when a particular event occurs Returned boolean value indicates whether the handler needs to be called again False value indicated that it needs to be removed and never called again

func Always added in v0.10.0

func Always(fn func(ctx context.Context, message interface{})) Handler

Always returns a handler wrapper that always gets executed by an event loop

func Once added in v0.10.0

func Once(fn func(ctx context.Context, message interface{})) Handler

Once returns a handler wrapper that gets executed only once by an event loop

type ID added in v0.10.0

type ID int

ID represents a unique event ID

func New added in v0.10.0

func New(name string) ID

type Listener added in v0.10.0

type Listener struct {
	ID      ListenerID
	EventID ID
	Handler Handler
}

Listener is an internal listener representation

type ListenerID added in v0.10.0

type ListenerID int

ListenerID is an internal listener ID that can be used to unsubscribe from a particular event

type Loop added in v0.10.0

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

func NewLoop added in v0.10.0

func NewLoop(sources ...SourceFactory) *Loop

func (*Loop) AddListener added in v0.10.0

func (loop *Loop) AddListener(eventID ID, handler Handler) ListenerID

func (*Loop) Listeners added in v0.16.0

func (loop *Loop) Listeners(eventID ID) int

func (*Loop) RemoveListener added in v0.10.0

func (loop *Loop) RemoveListener(eventID ID, listenerID ListenerID)

func (*Loop) Run added in v0.12.0

func (loop *Loop) Run(ctx context.Context) error

type Source added in v0.10.0

type Source interface {
	rpcc.Stream
	Recv() (Event, error)
}

Source represents a custom source of system events

func NewStreamSource added in v0.16.0

func NewStreamSource(
	eventID ID,
	stream rpcc.Stream,
	decoder StreamDecoder,
) Source

NewStreamSource create a new custom event source based on rpcc.Stream eventID - is a unique event ID stream - is a custom event stream decoder - is a value conversion function

type SourceFactory added in v0.16.0

type SourceFactory func(ctx context.Context) (Source, error)

SourceFactory represents a function that creates a new instance of Source.

func NewStreamSourceFactory added in v0.16.0

func NewStreamSourceFactory(eventID ID, factory StreamFactory, receiver StreamDecoder) SourceFactory

type StreamDecoder added in v0.16.0

type StreamDecoder func(stream rpcc.Stream) (interface{}, error)

type StreamFactory added in v0.16.0

type StreamFactory func(ctx context.Context) (rpcc.Stream, error)

type StreamSource added in v0.16.0

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

StreamSource represents a helper struct for generating custom event sources

func (*StreamSource) Close added in v0.16.0

func (src *StreamSource) Close() error

func (*StreamSource) ID added in v0.16.0

func (src *StreamSource) ID() ID

func (*StreamSource) Ready added in v0.16.0

func (src *StreamSource) Ready() <-chan struct{}

func (*StreamSource) Recv added in v0.16.0

func (src *StreamSource) Recv() (Event, error)

func (*StreamSource) RecvMsg added in v0.16.0

func (src *StreamSource) RecvMsg(m interface{}) error

type WaitTask

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

func NewEvalWaitTask

func NewEvalWaitTask(
	ec *eval.Runtime,
	fn *eval.Function,
	polling time.Duration,
) *WaitTask

func NewWaitTask

func NewWaitTask(
	fun Function,
	polling time.Duration,
) *WaitTask

func (*WaitTask) Run

func (task *WaitTask) Run(ctx context.Context) (core.Value, error)

Jump to

Keyboard shortcuts

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