Documentation
¶
Overview ¶
Package hub provides a simple event dispatcher for publish/subscribe pattern.
Example ¶
package main
import (
"fmt"
)
// Different event kinds
const (
happenedA = iota
happenedB
happenedC
)
// Our custom event type
type EventA struct {
arg1, arg2 int
}
// Implement hub.Event interface
func (e EventA) Kind() int { return happenedA }
func main() {
Subscribe(happenedA, func(e Event) {
a := e.(EventA) // Cast to concrete type
fmt.Println(a.arg1 + a.arg2)
})
Publish(EventA{2, 3})
}
Output: 5
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultHub = New()
DefaultHub is the default Hub used by Publish and Subscribe.
Functions ¶
Types ¶
Click to show internal directories.
Click to hide internal directories.

