event

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2018 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatcher

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

Dispatcher is a distributor of events to registered handlers. A handler is a event-type-specific function that takes the concrete type of an event as a parameter.

func NewDispatcher

func NewDispatcher() *Dispatcher

NewDispatcher returns a new instance.

func (*Dispatcher) Event

func (dispatcher *Dispatcher) Event(e Event)

Event dispatches the given event to all currently registered handlers.

func (*Dispatcher) RegisterHandler

func (dispatcher *Dispatcher) RegisterHandler(handlerFunc interface{}) func()

RegisterHandler must be called a function that takes one argument which is a concrete structural type (implementing the Event interface). This function panics if this is not fulfilled. The same handler function can be registered several times for the same type. It will be called for each registration.

The returned function can be used to unregister the handler again. It is a closure over UnregisterHandler(eType, handlerFunc).

func (*Dispatcher) UnregisterHandler

func (dispatcher *Dispatcher) UnregisterHandler(handlerFunc interface{})

UnregisterHandler removes a handler that was previously registered. If there was no registration done, this call is ignored. If the same handler was registered multiple times, all registrations are removed.

type Event

type Event interface{}

Event describes something to be dispatched.

type Listener

type Listener interface {
	Event(e Event)
}

Listener receives events.

type Queue

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

Queue stores events to be dispatched at a later time.

func (*Queue) Event

func (queue *Queue) Event(e Event)

Event queues the given event at the tail. When events are dispatched, they are so first-in, first-out (FIFO). nil events are ignored. Typed event pointer that are nil are not ignored.

func (*Queue) ForwardTo

func (queue *Queue) ForwardTo(listener Listener)

ForwardTo forwards all currently queued events to the given listener. If there are new events added to the queue during this call, they will be put on hold, to be dispatched during a next call.

func (Queue) IsEmpty

func (queue Queue) IsEmpty() bool

IsEmpty returns true if there are no more events pending.

type Registry added in v0.3.0

type Registry interface {
	// RegisterHandler must be called a function that takes one argument which is
	// a concrete structural type (implementing the Event interface).
	// This function panics if this is not fulfilled.
	// The same handler function can be registered several times for the same type.
	// It will be called for each registration.
	//
	// The returned function can be used to unregister the handler again.
	RegisterHandler(handlerFunc interface{}) func()
}

Registry describes an entity where an event handler can be registered.

Jump to

Keyboard shortcuts

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