Documentation ¶
Overview ¶
Package signal implements functions for emitting and receiving signals on events. Gondola provides some builtin signals, but users can define additional ones
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Emit ¶
func Emit(name string, object interface{})
Emit calls all the listeners for the given signal.
func Stop ¶
Stop removes a listener, previously registered using Listen. The first argument indicates the signal name. If it's empty, the listener will be removed for all the signal. The second argument is the token returned by Listen(). If it's empty, all the listeners for the given signals will be removed.
Types ¶
type Token ¶
type Token struct {
// contains filtered or unexported fields
}
func Listen ¶
Listen adds a new listener for the given signal name. The second argument must be a function which accepts either:
- no paremeters - 1 parameter, which must be of type string - 2 parameters, the first one must be string and the second one, interface{}
If the function does not match the required constraints, Listen will panic.
The function will be called whenever the signal is emitted. The returned value is the token, which is required to unregister this listener. If you don't need to unregister it, you can safely ignore the first returned value.