Closed nvnamsss closed 4 years ago
Event
is designing as a struct, the basic Event
has a list
of callback and a variable determine the style of trigger
type Event struct {
Async bool
callbacks map[string]func()
}
Methods
:
Subscribe(callback func())
: Subscribe the callback functionUnsubscribe(callback func())
: Unsubscribe the callback function if it been subscribedInvoke()
": Trigger all subscribed callbacks. If trigger type is async, all subscribed callback will run by goroutine. Otherwise, it will be sequentially run
Need a module for event-drivent pattern in Go.