events

package
v0.0.0-...-58d1483 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2017 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SendEvent

func SendEvent(receiver Receiver, event Event)

SendEvent performs the event loop on a receiver to completion

Types

type Event

type Event interface{}

Event is a type meant to clearly convey that the return type or parameter to a function will be supplied to/from an events.Manager

type Manager

type Manager interface {
	Inject(Event)         // A temporary interface to allow the event manager thread to skip the queue
	Queue() chan<- Event  // Get a write-only reference to the queue, to submit events
	SetReceiver(Receiver) // Set the target to route events to
	Start()               // Starts the Manager thread TODO, these thread management things should probably go away
	Halt()                // Stops the Manager thread
}

Manager provides a serialized interface for submitting events to a Receiver on the other side of the queue

func NewManagerImpl

func NewManagerImpl() Manager

NewManagerImpl creates an instance of managerImpl

type Receiver

type Receiver interface {
	// ProcessEvent delivers an event to the Receiver, if it returns non-nil, the return is the next processed event
	ProcessEvent(e Event) Event
}

Receiver is a consumer of events, ProcessEvent will be called serially as events arrive

type Timer

type Timer interface {
	SoftReset(duration time.Duration, event Event) // start a new countdown, only if one is not already started
	Reset(duration time.Duration, event Event)     // start a new countdown, clear any pending events
	Stop()                                         // stop the countdown, clear any pending events
	Halt()                                         // Stops the Timer thread
}

Timer is an interface for managing time driven events the special contract Timer gives which a traditional golang timer does not, is that if the event thread calls stop, or reset then even if the timer has already fired, the event will not be delivered to the event queue

type TimerFactory

type TimerFactory interface {
	CreateTimer() Timer // Creates an Timer which is stopped
}

TimerFactory abstracts the creation of Timers, as they may need to be mocked for testing

func NewTimerFactoryImpl

func NewTimerFactoryImpl(manager Manager) TimerFactory

NewTimerFactoryImpl creates a new TimerFactory for the given Manager

Jump to

Keyboard shortcuts

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