github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/utilities/event/example_test.go (about) 1 package event 2 3 import "fmt" 4 5 func ExampleTypeMux() { 6 type someEvent struct{ I int } 7 type otherEvent struct{ S string } 8 type yetAnotherEvent struct{ X, Y int } 9 10 var mux TypeMux 11 12 done := make(chan struct{}) 13 sub := mux.Subscribe(someEvent{}, otherEvent{}) 14 go func() { 15 for event := range sub.Chan() { 16 fmt.Printf("Received: %#v\n", event.Data) 17 } 18 fmt.Println("done") 19 close(done) 20 }() 21 22 mux.Post(someEvent{5}) 23 mux.Post(yetAnotherEvent{X: 3, Y: 4}) 24 mux.Post(someEvent{6}) 25 mux.Post(otherEvent{"whoa"}) 26 27 mux.Stop() 28 29 <-done 30 31 }