event

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package event provides an event dispatcher for the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatcher

type Dispatcher interface {
	// Dispatch sends an event to all registered handlers.
	Dispatch(ctx context.Context, event Event) error

	// Subscribe registers a handler for the given event type.
	Subscribe(eventType EventType, handler Handler)

	// Unsubscribe removes a handler from the given event type.
	Unsubscribe(eventType EventType, handler Handler)
}

Dispatcher dispatches events to registered handlers.

func NewDispatcher

func NewDispatcher() Dispatcher

NewDispatcher creates a new event dispatcher.

func NewNoOpDispatcher

func NewNoOpDispatcher() Dispatcher

NewNoOpDispatcher creates a new no-op dispatcher.

type Event

type Event struct {
	Type      EventType
	Payload   any
	Timestamp time.Time
}

Event represents an application event.

func NewEvent

func NewEvent(eventType EventType, payload any) Event

NewEvent creates a new event with the current timestamp.

type EventType

type EventType string

EventType represents the type of an event.

const (
	EventJobCreated   EventType = "job.created"
	EventJobScheduled EventType = "job.scheduled"
	EventJobStarted   EventType = "job.started"
	EventJobCompleted EventType = "job.completed"
	EventJobFailed    EventType = "job.failed"
	EventJobCancelled EventType = "job.cancelled"
	EventJobRetrying  EventType = "job.retrying"
)

Job lifecycle events.

type Handler

type Handler func(ctx context.Context, event Event) error

Handler is a function that handles an event.

type NoOpDispatcher

type NoOpDispatcher struct{}

NoOpDispatcher is a dispatcher that does nothing. Useful for testing or when events are not needed.

func (*NoOpDispatcher) Dispatch

func (d *NoOpDispatcher) Dispatch(_ context.Context, _ Event) error

Dispatch does nothing.

func (*NoOpDispatcher) Subscribe

func (d *NoOpDispatcher) Subscribe(_ EventType, _ Handler)

Subscribe does nothing.

func (*NoOpDispatcher) Unsubscribe

func (d *NoOpDispatcher) Unsubscribe(_ EventType, _ Handler)

Unsubscribe does nothing.

Directories

Path Synopsis
Package builder provides a fluent API for constructing events.
Package builder provides a fluent API for constructing events.
Package bus provides the core event bus functionality for pub/sub messaging.
Package bus provides the core event bus functionality for pub/sub messaging.
Package dispatcher provides event dispatching with persistence.
Package dispatcher provides event dispatching with persistence.
Package handlers provides specialized event handlers for complex event processing.
Package handlers provides specialized event handlers for complex event processing.
Package repository provides data access for events.
Package repository provides data access for events.
Package subscribers provides built-in event subscribers.
Package subscribers provides built-in event subscribers.

Jump to

Keyboard shortcuts

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