lifecycle.go 374 B

12345678910111213141516171819202122
  1. package lifecycle
  2. type Event int
  3. const (
  4. ApplicationStarting Event = iota
  5. ApplicationStarted
  6. )
  7. type EventHandlerFunc func()
  8. var listeners = map[int][]EventHandlerFunc{}
  9. func AddListener(evt Event, fn EventHandlerFunc) {
  10. listeners[int(evt)] = append(listeners[int(evt)], fn)
  11. }
  12. func Notify(evt Event) {
  13. for _, handler := range listeners[int(evt)] {
  14. handler()
  15. }
  16. }