ebus

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

README

ebus

The package ebus for Go provides a generic and type-safe event bus for publishing and subscribing to events within a single process without any guarantees to durability or delivery.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Emit

func Emit[T Event](bus *Bus, ev T)

Emit sends the given event to all subscribers of the given event type.

Types

type Bus

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

func New

func New() *Bus

type Event

type Event interface {
	// Type always returns the same EventType for the given Event type.
	Type() EventType
}

Event is a message on the Bus identified by an EventType value.

type EventType

type EventType interface {
	Hash() uintptr
	Equals(other EventType) bool
}

type StopFn

type StopFn func()

StopFn is called to stop receiving any further events.

func On

func On[T Event](bus *Bus, cb func(T)) StopFn

On subscribes a given handler to a given event type on the given bus.

func SubscribeTo

func SubscribeTo[T Event](bus *Bus, qsize int, et EventType, cb func(T)) StopFn

SubscribeTo subscribes to an event with the specified event type.

Jump to

Keyboard shortcuts

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