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)
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
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.
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |