Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
| 1 |
package hub_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
|
| 6 |
"github.com/cenkalti/hub" |
| 7 |
) |
| 8 |
|
| 9 |
// Different event kinds |
| 10 |
const ( |
| 11 |
happenedA hub.Kind = iota |
| 12 |
happenedB |
| 13 |
happenedC |
| 14 |
) |
| 15 |
|
| 16 |
// Our custom event type |
| 17 |
type EventA struct { |
| 18 |
arg1, arg2 int |
| 19 |
} |
| 20 |
|
| 21 |
// Implement hub.Event interface |
| 22 |
func (e EventA) Kind() hub.Kind { return happenedA } |
| 23 |
|
| 24 |
func Example() { |
| 25 |
hub.Subscribe(happenedA, func(e hub.Event) { |
| 26 |
a := e.(EventA) // Cast to concrete type |
| 27 |
fmt.Println(a.arg1 + a.arg2) |
| 28 |
}) |
| 29 |
|
| 30 |
hub.Publish(EventA{2, 3}) |
| 31 |
// Output: 5 |
| 32 |
} |