events

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Purpose: This file implements the Spark EventDispatcher subsystem for the GoStack framework. It provides a synchronous and asynchronous Pub/Sub communication channel.

Philosophy: Ecosystem decoupling is critical for clean application code. By dispatching events instead of coupling business components directly, we preserve single-responsibility rules. The dispatcher is written using standard mutexes to ensure high-performance, concurrent-safe registrations and publishing.

Architecture: A standalone framework package (`github.com/Charledeon77/gostack/framework/events`). Implements the `contract.EventDispatcher` interface.

Choice: We chose a map-of-slices design with read/write mutexes rather than a channel-based multiplexer to guarantee immediate synchronous dispatch order when requested (which is crucial for database transactions) while offering clean `DispatchAsync` hooks for non-blocking processes.

Implementation: - Dispatcher: coordinates event listening and firing.

  • Listen(): registers a Listener to a specific event category.
  • Dispatch(): fires the event executing all handlers synchronously in the same thread.
  • DispatchAsync(): fires all registered event handlers in separate background goroutines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatcher

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

Dispatcher manages event-listener mappings safely across concurrent HTTP handlers.

func NewDispatcher

func NewDispatcher() *Dispatcher

NewDispatcher initializes an empty, thread-safe Dispatcher instance.

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(eventName string, event any) error

Dispatch executes all listeners registered to eventName synchronously. If any listener returns an error, execution stops and that error is returned.

func (*Dispatcher) DispatchAsync

func (d *Dispatcher) DispatchAsync(eventName string, event any, errHandler func(error))

DispatchAsync fires all registered listeners in their own concurrent background goroutines. It returns immediately and executes asynchronously, logging errors via a user-definable callback or standard runtime recovery.

func (*Dispatcher) Listen

func (d *Dispatcher) Listen(eventName string, listener contract.Listener)

Listen registers a listener function to run when a specific event name is fired.

Jump to

Keyboard shortcuts

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