Fast, In-Process Event Dispatcher This package offers a high-performance, in-process event dispatcher for Go, ideal for decoupling modules and enabling asynchronous event handling. It supports both synchronous and asynchronous processing, focusing on speed and simplicity. High Performance: Processes millions of events per second, about 4x to 10x faster than channels. Processes millions of events per second, about than channels. Generic: Works with any type implementing the Event interface. Works with any type implementing the interface. Asynchronous: Each subscriber runs in its own goroutine, ensuring non-blocking event handling. Use When: ✅ Decoupling modules within a single Go process. ✅ Implementing lightweight pub/sub or event-driven patterns. ✅ Needing high-throughput, low-latency event dispatching. ✅ Preferring a simple, dependency-free solution. Not For: ❌ Inter-process/service communication (use Kafka, NATS, etc.). ❌ Event persistence, durability, or advanced routing/filtering. ❌ Cross-language/platform scenarios. ❌ Event replay, dead-letter queues, or deduplication. ❌ Heavy subscribe/unsubscribe churn or massive dynamic subscriber counts. Generic In-Process Pub/Sub This repository contains a simple, in-process event dispatcher to be used to decouple internal modules. It provides a generic way to define events, publish and subscribe to them. // Various event types const EventA = 0x01 // Event type for testing purposes type myEvent struct { Data string } // Type returns the event type func ( ev myEvent ) Type () uint32 { return EventA } Using Default Dispatcher For convenience, this package provides a default global dispatcher that can be used with On() and Emit() package-level functions. // Subcribe to event A, and automatically unsubscribe at the end defer event . On ( func ( e Event ) { println ( "(consumer)" , e . Data ) })() // Publish few events event . Emit ( newEventA ( "event 1" )) event . Emit ( newEventA ( "event 2" )) event . Emit ( newEventA ( "e...
First seen: 2025-06-29 17:37
Last seen: 2025-06-30 05:45