olebedev / emitter

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

Add result to event #13

Closed albulescu closed 4 years ago

albulescu commented 4 years ago

Don't know if is the right approach for:

e.On("upload", function(ev *emitter.Emitter) {
   // Processing upload and return result
  ev.Result <- errors.New("Some error")
  // or
  ev.Result <- &CustomResult{}
});

ch := e.Emit("upload", file, header)

select {
case v := <-ch:
    fmt.Println("Result:", v)
case <-time.After(time.Second):
    fmt.Println("Timeout")
}

// Also the following might be helpful

bus.On("test", func(ev *Event, a, b int) {}) // Maybe event optional
bus.Emit("test", 1, 2)