event

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

The code in event was originally a part of https://github.com/kelindar/event (v1.5.2)

The original code uses a time.Ticker to process the event queue which caused a large increase in CPU usage (#189). This code was ported to remove the ticker and instead be more event driven.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = NewDispatcherConfig(25000)

Default initializes a default in-process dispatcher

Functions

func Emit

func Emit[T Event](ev T)

Emit writes an event into the dispatcher. This functions same way as Publish() but uses the default dispatcher instead.

func On

func On[T Event](handler func(T)) context.CancelFunc

On subscribes to an event, the type of the event will be automatically inferred from the provided type. Must be constant for this to work. This functions same way as Subscribe() but uses the default dispatcher instead.

func OnType

func OnType[T Event](eventType uint32, handler func(T)) context.CancelFunc

OnType subscribes to an event with the specified event type. This functions same way as SubscribeTo() but uses the default dispatcher instead.

func Publish

func Publish[T Event](broker *Dispatcher, ev T)

Publish writes an event into the dispatcher

func Subscribe

func Subscribe[T Event](broker *Dispatcher, handler func(T)) context.CancelFunc

Subscribe subscribes to an event, the type of the event will be automatically inferred from the provided type. Must be constant for this to work.

func SubscribeTo

func SubscribeTo[T Event](broker *Dispatcher, eventType uint32, handler func(T)) context.CancelFunc

SubscribeTo subscribes to an event with the specified event type.

Types

type Dispatcher

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

Dispatcher represents an event dispatcher.

func NewDispatcher

func NewDispatcher() *Dispatcher

NewDispatcher creates a new dispatcher of events.

func NewDispatcherConfig

func NewDispatcherConfig(maxQueue int) *Dispatcher

NewDispatcherConfig creates a new dispatcher with configurable max queue size

func (*Dispatcher) Close

func (d *Dispatcher) Close() error

Close closes the dispatcher

type Event

type Event interface {
	Type() uint32
}

Event represents an event contract

Jump to

Keyboard shortcuts

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