package hub

Import Path
	github.com/cenkalti/hub (on go.dev)

Dependency Relation
	imports one package, and imported by one package

Involved Source Files Package hub provides a simple event dispatcher for publish/subscribe pattern.
Code Examples package main import ( "fmt" "github.com/cenkalti/hub" ) // Different event kinds const ( happenedA hub.Kind = iota happenedB happenedC ) // Our custom event type type EventA struct { arg1, arg2 int } // Implement hub.Event interface func (e EventA) Kind() hub.Kind { return happenedA } func main() { hub.Subscribe(happenedA, func(e hub.Event) { a := e.(EventA) // Cast to concrete type fmt.Println(a.arg1 + a.arg2) }) hub.Publish(EventA{2, 3}) }
Package-Level Type Names (total 3)
/* sort by: | */
Event is an interface for published events. ( Event) Kind() Kind func Publish(e Event) func (*Hub).Publish(e Event)
Hub is an event dispatcher, publishes events to the subscribers which are subscribed for a specific event type. Optimized for publish calls. The handlers may be called in order different than they are registered. Publish an event to the subscribers. Subscribe registers f for the event of a specific kind. var DefaultHub
func Event.Kind() Kind func Subscribe(kind Kind, f func(Event)) (cancel func()) func (*Hub).Subscribe(kind Kind, f func(Event)) (cancel func())
Package-Level Functions (total 2)
Publish an event to the subscribers in DefaultHub.
Subscribe registers f for the event of a specific kind in the DefaultHub.
Package-Level Variables (only one)
DefaultHub is the default Hub used by Publish and Subscribe.