eventbus

package
v0.0.0-...-8c3d3b4 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: MIT Imports: 3 Imported by: 3

README

eventbus

This is a small event bus library. You should be able to figure our how to use it just by looking at bus.go and event.go.

Documentation

Index

Constants

View Source
const (

	// EHANDLE_OK means that the event should not be cancelled.
	EHANDLE_OK = 0

	// EHANDLE_CANCEL means that the event should be cancelled.
	EHANDLE_CANCEL = 1
)
View Source
const (

	// EFLAG_NORMAL means this is a normal sync event.
	EFLAG_NORMAL = 0

	// EFLAG_UNCANCELLABLE means that the event cannot be cancelled.
	EFLAG_UNCANCELLABLE = 1 << 0

	// EFLAG_ASYNC_UNSAFE means that the event is an async event.  Don't use declaritvely.
	EFLAG_ASYNC_UNSAFE = 1 << 1 // Don't use this directly!

	// EFLAG_ASYNC means thtat the event will be processed asychronously.
	EFLAG_ASYNC = EFLAG_ASYNC_UNSAFE | EFLAG_UNCANCELLABLE
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event interface {
	Name() string
	Flags() uint8
}

An Event is a description of "something" that has taken place.

type EventBus

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

An EventBus takes events and forwards them to event handlers matched by name.

func NewEventBus

func NewEventBus() EventBus

NewEventBus creates a new event bus without any event handlers.

func (*EventBus) CountHandlers

func (b *EventBus) CountHandlers(name string) int

CountHandlers is a convenience function.

func (*EventBus) Publish

func (b *EventBus) Publish(event Event) (bool, error)

Publish sends an event to the relevant event handlers.

func (*EventBus) PublishNonblocking

func (b *EventBus) PublishNonblocking(event Event) error

PublishNonblocking sends async events off to the relevant handlers witout blocking.

func (*EventBus) RegisterHandler

func (b *EventBus) RegisterHandler(eventName string, hFunc func(Event) EventHandleResult)

RegisterHandler registers an event handler function by name

type EventHandleResult

type EventHandleResult uint8

EventHandleResult is a flag field to represent certain things.

Jump to

Keyboard shortcuts

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