events

package
v0.0.0-...-d9e9996 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package events is the event center for internal system events. All modules could register event callback for each event.

Index

Constants

View Source
const (

	/* Events for consensus, start from 1000 */
	// ProposerReady current consensus proposers ready for use
	ProposerReady = 1000
	// ProposerChanged next round consensus proposers ready for use
	ProposerChanged = 1010
)

Definition for internal system events

Variables

View Source
var (
	ErrInvalidParams    = errors.New("Invalid Params")
	ErrQueueFull        = errors.New("Event queue is full")
	ErrDuplicateHandler = errors.New("Duplicate handler")
	ErrPartialSuccess   = errors.New("Operations partial success")
)

Event center errors

Functions

This section is empty.

Types

type EventBus

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

EventBus is the event hub for all registered events

func GetEventBus

func GetEventBus() *EventBus

GetEventBus return the instance of EventBus

func (*EventBus) FireEvent

func (ec *EventBus) FireEvent(em *EventMessage) error

FireEvent trigger a new event message to registerred handlers

func (*EventBus) FireEventAsync

func (ec *EventBus) FireEventAsync(em *EventMessage) (*sync.WaitGroup, error)

FireEventAsync trigger a new event message to registerred handlers asynchronous

func (*EventBus) Subscribe

func (ec *EventBus) Subscribe(eType EventType, handler EventHandler) error

Subscribe specified event type with a handler

func (*EventBus) SubscribeMulti

func (ec *EventBus) SubscribeMulti(eTypes []EventType, handler EventHandler) ([]EventType, error)

SubscribeMulti subscribe multiple events with one handler

func (*EventBus) Unsubscribe

func (ec *EventBus) Unsubscribe(eType EventType, handler EventHandler) error

Unsubscribe the given event handler of specified event type

func (*EventBus) UnsubscribeMulti

func (ec *EventBus) UnsubscribeMulti(eTypes []EventType, handler EventHandler) ([]EventType, error)

UnsubscribeMulti unsubscribe multiple events with given handler

type EventHandler

type EventHandler func(e *EventMessage)

EventHandler define the message handler

type EventMessage

type EventMessage struct {
	BcName   string
	Type     EventType
	Priority uint
	Sender   interface{}
	Message  interface{}
}

EventMessage is the event message body

type EventType

type EventType uint

EventType event type definition

Jump to

Keyboard shortcuts

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