events

package
v0.16.0-rc.6 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2021 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

This section is empty.

Types

type DataStreamReceiver

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

type Event

type Event struct {
	ID   ID
	Data interface{}
}

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

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) (context.CancelFunc, 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,
	receiver DataStreamReceiver,
) Source

NewStreamSource create a new custom event source based on rpcc.Stream eventID - is a unique event ID stream - is a custom event stream receiver - 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 DataStreamReceiver) SourceFactory

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 NewCallWaitTask

func NewCallWaitTask(
	ec *eval.Runtime,
	fn *eval.CompiledFunction,
	polling time.Duration,
) *WaitTask

func NewEvalWaitTask

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

func NewValueWaitTask added in v0.7.0

func NewValueWaitTask(
	when drivers.WaitEvent,
	value core.Value,
	getter 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