bus

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package bus is an implementation of an event bus.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

type Bus[EM Emittable, SU Subscriber[EM]] struct {
	// contains filtered or unexported fields
}

func NewBus

func NewBus[EM Emittable, SU Subscriber[EM]](opts ...Option) *Bus[EM, SU]

func (*Bus[EM, SU]) Post

func (b *Bus[EM, SU]) Post(em EM, priority uint8)

func (*Bus[EM, SU]) Size

func (b *Bus[EM, SU]) Size() int

func (*Bus[EM, SU]) Subscribe

func (b *Bus[EM, SU]) Subscribe(s SU)

func (*Bus[EM, SU]) Tick

func (b *Bus[EM, SU]) Tick()

func (*Bus[EM, SU]) Unsubscribe

func (b *Bus[EM, SU]) Unsubscribe(s SU)

type Emittable

type Emittable interface {
	ID() uuid.UUID
	Topic() string
	Cancel()
	Canceled() bool
}

An Emittable is any type that can be emitted and routed by a Bus.

type Option

type Option func(*Options)

func WithDemuxers

func WithDemuxers(n int) Option

func WithErrorBuilder

func WithErrorBuilder(builder func(error) Emittable) Option

type Options

type Options struct {
	Demuxers     int
	ErrorBuilder func(error) Emittable
}

func NewOptions

func NewOptions(opts ...Option) *Options

type PriorityQueue

type PriorityQueue[P cmp.Ordered, V any] interface {
	Push(elem V, priority P)
	Pop() (V, bool)
	Peek() V
	Size() int
	Clear()
}

A PriorityQueue is any data structure that can store and retrieve elements in order of priority.

type Subscriber

type Subscriber[EM Emittable] interface {
	ID() uuid.UUID
	Topic() string
	Handle(em EM) error
}

A Subscriber is any type that can receive and handle Emittable types.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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