<aside> ❗ Instead of the manuell way, you can use the https://github.com/asaskevich/EventBus Repository but consider that this repository is not maintained anymore.

</aside>

With Channels you can create listener, witch are listen for events in the channels. Instead of a global-Notifier or Logger, use a listener.

The first thing to do is to create a channel that can interact with multiple threads. This channel can then be written to from anywhere. For the listener a function must be created on a new thread, so that the runtime is not blocked. In this function there is an infinity loop which always checks if the channel contains something. If yes then something is executed (e.g. logged to the console, or written to Sentry), otherwise it is simply skipped. If the content has been interacted with, it is deleted from the channel so that the buffer doesn't get too big.

errChan := make(chan error)
	go func() {
		for err := range errChan {
			if err != nil {
				fmt.Println(err)
			}
			select {
			case <-time.After(0):
				select {
				case <-errChan:
				default:
				}
			}
		}
	}()
	errChan <- errors.New("error chan 1")

	go func() {
		time.Sleep(3 * time.Second)
		errChan <- errors.New("error chan 2")
		time.Sleep(3 * time.Second)
		errChan <- errors.New("error chan 3")
		time.Sleep(3 * time.Second)
		errChan <- errors.New("error chan 4")
		time.Sleep(3 * time.Second)
		errChan <- errors.New("error chan 5")
		time.Sleep(3 * time.Second)
		errChan <- errors.New("error chan 6")
		time.Sleep(3 * time.Second)
		errChan <- errors.New("error chan 7")
		time.Sleep(3 * time.Second)
		errChan <- errors.New("error chan 8")
		time.Sleep(3 * time.Second)
		errChan <- errors.New("error chan 9")
	}()

	errChan <- errors.New("error chan 10")

old Code