Generic event emitter/dispatcher in Go

Go doesn’t support generics, one can use go generate, but writing code for that is a pain. Instead we can tinker with reflection to manipulate types and channels. This allows us to create neat event dispatcher with user friendly handler registration and somewhat reasonable event registration. Event emitters are pretty popular in OOP languages which support generics, but of course Go is not one of them. We will try to achieve something similar without generic types....

December 26, 2015 · 6 min