olebedev / emitter

Emits events in Go way, with wildcard, predicates, cancellation possibilities and many other good wins
Other
509 stars 33 forks source link

how to transfer object into the listener #9

Closed jjhesk closed 6 years ago

jjhesk commented 6 years ago

e := &ev.Emitter{} e.Use("*", ev.Void)

e.On("main_event", func(evt *ev.Event) { message_like := evt.Args[0] jscontent, := json.Marshal(message_like) fmt.Printf("\nBC mess:", js_content) })

type Announcement struct { GameID int json:"gid" PlayerId int64 json:"pid" }

b1 := &Announcement{ GameID: 1, PlayerId: 4234, } go ev.Emit("main_event", b1)

how to cast the type into the receive listener?

olebedev commented 6 years ago

b2, ok := e.Args[0].(*Announcement)

jjhesk commented 6 years ago

ok, thats really useful!