Documentation ¶
Index ¶
- type EventEmitter
- func (self *EventEmitter) AddListener(event string, listener interface{})
- func (self *EventEmitter) Emit(event string, argv ...interface{}) <-chan *Response
- func (self *EventEmitter) Init()
- func (self *EventEmitter) Listeners(event string) []reflect.Value
- func (self *EventEmitter) On(event string, listener interface{})
- func (self *EventEmitter) RemoveListeners(event string)
- type Response
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventEmitter ¶
type EventEmitter struct {
// contains filtered or unexported fields
}
Example ¶
// Construct a new EventEmitter instance emitter := New() emitter.On("hello", func() { fmt.Println("Hello World") }) emitter.On("hello", func() { fmt.Println("Hello Hello World") }) // Wait until all handlers have finished <-emitter.Emit("hello")
Output: Hello World Hello Hello World
func New ¶
func New() *EventEmitter
func (*EventEmitter) AddListener ¶
func (self *EventEmitter) AddListener(event string, listener interface{})
AddListener adds an event listener on the given event name.
func (*EventEmitter) Emit ¶
func (self *EventEmitter) Emit(event string, argv ...interface{}) <-chan *Response
Emits the given event. Puts all arguments following the event name into the Event's `Argv` member. Returns a channel if listeners were called, nil otherwise.
Example ¶
emitter := New() emitter.On("hello", func(name string) { fmt.Printf("Hello World %s\n", name) }) <-emitter.Emit("hello", "John")
Output: Hello World John
func (*EventEmitter) Init ¶
func (self *EventEmitter) Init()
Allocates the EventEmitters memory. Has to be called when embedding an EventEmitter in another Type.
Example ¶
package main type SampleServer struct { EventEmitter } func NewServer() *Server { s := new(Server) // Initialize Maps s.EventEmitter.Init() return s } func main() { s := NewServer() // Do something s.Emit("connect" /*, conn */) }
Output:
func (*EventEmitter) On ¶
func (self *EventEmitter) On(event string, listener interface{})
Alias to AddListener.
func (*EventEmitter) RemoveListeners ¶
func (self *EventEmitter) RemoveListeners(event string)
Removes all listeners from the given event.
Click to show internal directories.
Click to hide internal directories.