events

package
v0.0.0-...-f32f910 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2022 License: MIT Imports: 2 Imported by: 1

README

Events

The events package provides a dispatcher and event interface that allows code to implement the observer pattern. See Event Dispatcher in Go for more details.

Documentation

Overview

Package events provides an event dispatcher and registration framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func(Event) error

Callback is a function that can receive events.

type Dispatcher

type Dispatcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Dispatcher objects can register callbacks for specific events, then when those events occur, dispatch them to all callback functions.

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(etype Type, value interface{}) error

Dispatch an event, ensuring that the event is properly formatted. Currently this method simply warns if there is an error. TODO: return list of errors or do better error handling.

func (*Dispatcher) Init

func (d *Dispatcher) Init(source interface{})

Init a dispatcher with the source, creating the callbacks map.

func (*Dispatcher) Register

func (d *Dispatcher) Register(etype Type, callback Callback)

Register a callback function for the specified event type.

func (*Dispatcher) Remove

func (d *Dispatcher) Remove(etype Type, callback Callback)

Remove a callback function for the specified event type.

type Event

type Event interface {
	Type() Type
	Source() interface{}
	Value() interface{}
}

Event represents actions that occur during consensus. Listeners can register callbacks with event handlers for specific event types.

type Type

type Type uint16

Type is an enumeration of the kind of events that can occur.

const (
	UnknownEvent Type = iota
	TimeoutEvent
)

Some standard event types

func (Type) String

func (t Type) String() string

String returns the name of event types

Jump to

Keyboard shortcuts

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