Open eyudkin opened 6 years ago
ping @olebedev
@tensor146
Emitting seems to block the go-routine you're calling from, but you can emit from another go-routine
package main
import (
"fmt"
"github.com/olebedev/emitter"
)
func main() {
e := &emitter.Emitter{}
go func() {
<-e.Emit("change", 42) // wait for the event sent successfully
<-e.Emit("change", 37)
e.Off("*") // unsubscribe any listeners
}()
for event := range e.On("change") {
fmt.Println(event.Int(0)) // cast the first argument to int
go func() {
e.Emit("change", 100)
}()
}
// listener channel was closed
}
There is example: https://play.golang.org/p/d0jXdhwwfrU
Output: