event

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2020 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initialize

func Initialize(m *plugin.Manager) (plugin.Plugin, error)

Types

type Dispatcher

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

Dispatcher binds functions to be called indirectly by unrelated code.

func FromPlugins

func FromPlugins(m *plugin.Manager) (*Dispatcher, error)

func NewDispatcher

func NewDispatcher() *Dispatcher

NewDispatcher returns an event dispatcher, ready for use.

func NewDispatcherLimit

func NewDispatcherLimit(limit int) *Dispatcher

NewDispatcherLimit returns an event dispatcher with a buffer size of limit.

func (*Dispatcher) Bind

func (d *Dispatcher) Bind(name string, handler Handler)

Bind adds the given handler to the list of handlersIndex for the event.

func (*Dispatcher) Emit

func (d *Dispatcher) Emit(name string, data map[string]interface{})

Emit will call bound handlersIndex for the given in event.

This method does not block unless the underlying channel becomes full. The map received by this method is not copied; avoid writing to it once it has been passed into this method.

func (*Dispatcher) Loop

func (d *Dispatcher) Loop()

Loop emits events in an infinite loop until the dispatcher is stopped.

If the Dispatcher is not running when Loop is called, it will be started. This method should be called in a separate goroutine. More than one worker can be started by calling this method multiple times in separate goroutines.

func (*Dispatcher) Stop

func (d *Dispatcher) Stop()

Stop signals to the dispatcher to stop emitting events.

All workers started with Loop will stop processing without draining the pending events.

func (*Dispatcher) Unbind

func (d *Dispatcher) Unbind(name string, handler Handler)

Unbind removes the given handler from the list of handlersIndex for the event.

type Event

type Event struct {
	Name string
	Data map[string]interface{}
	// contains filtered or unexported fields
}

An Event is used to pass data between an emitter and handler.

func (*Event) StopPropagation

func (e *Event) StopPropagation()

type Handler

type Handler interface {
	ID() string
	Handle(ev *Event)
}

A Handler is a uniquely identifiable function for handling an emitted event.

func HandlerFunc

func HandlerFunc(h func(ev *Event)) Handler

HandlerFunc returns a valid Handler using the given function.

Jump to

Keyboard shortcuts

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