eventmgr

package module
v0.0.0-...-0604790 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2017 License: ISC Imports: 1 Imported by: 1

README

eventmgr

This package assists with the subscription to, broadcast, and mutation of events, and is based on the events module of ircreactor.

Primarily designed for use with the GoshuIRC-Go library and IRC applications.


GoDoc Build Status Coverage Status Go Report Card

Documentation

Overview

Package eventmgr assists with the subscription to, broadcast, and mutation of events. Primarily designed for use with github.com/DanielOaks/girc-go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventHandler

type EventHandler struct {
	Handler  HandlerFn
	Priority int
}

EventHandler holds the priority and handler function of an event.

type EventManager

type EventManager struct {
	Events map[string]Handlers
}

EventManager lets you attach to and dispatch events.

func (*EventManager) Attach

func (manager *EventManager) Attach(event string, handler HandlerFn, priority int)

Attach lets you attach a handler to the given event.

func (*EventManager) Dispatch

func (manager *EventManager) Dispatch(event string, info map[string]interface{})

Dispatch dispatches the given event/info to all the matching event handlers.

type HandlerFn

type HandlerFn func(string, InfoMap)

HandlerFn defines a function we can call as a handler.

type Handlers

type Handlers struct {
	Handlers []EventHandler
}

Handlers holds a list of EventHandlers, including keeping them sorted.

func (Handlers) Attach

func (handlers Handlers) Attach(eventhandler EventHandler) Handlers

Attach attaches a handler to our internal list and returns a new Handlers.

This isn't optimised as much as we probably could. I think most event handlers will attach everything at startup, so it's not a massive issue, though it is something to look at.

func (Handlers) Dispatch

func (handlers Handlers) Dispatch(event string, info map[string]interface{})

Dispatch dispatches an event to all of our handlers.

func (Handlers) Len

func (handlers Handlers) Len() int

Len returns the length of the HandlerList

func (Handlers) Less

func (handlers Handlers) Less(i, j int) bool

Less returns whether i is less than j.

func (Handlers) Swap

func (handlers Handlers) Swap(i, j int)

Swap swaps i and j.

type InfoMap

type InfoMap map[string]interface{}

InfoMap defines a map we pass through event dispatches.

func NewInfoMap

func NewInfoMap() InfoMap

NewInfoMap returns a new, empty InfoMap.

Jump to

Keyboard shortcuts

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