35 lines
565 B
Go
35 lines
565 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
emitter "git.pyer.club/kingecg/goemitter"
|
|
)
|
|
|
|
type St struct {
|
|
Name string
|
|
}
|
|
|
|
func (s *St) Print(data ...interface{}) {
|
|
fmt.Println(s.Name)
|
|
fmt.Println(data...)
|
|
}
|
|
|
|
func main() {
|
|
|
|
s := &St{Name: "testeer"}
|
|
em := emitter.NewEmitter()
|
|
em.On("test", func(data ...interface{}) {
|
|
fmt.Println(data...)
|
|
})
|
|
|
|
em.On("test", s.Print)
|
|
em.Once("test", func(data ...interface{}) {
|
|
s := fmt.Sprint(data...)
|
|
fmt.Println(interface{}("Once"), s)
|
|
})
|
|
em.EmitSync("test", "hello", "world")
|
|
em.Emit("test", "hello", "world2")
|
|
select {}
|
|
}
|