Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler represents a handler for processing events.
func NewReadHandler ¶
func NewReadHandler(ch reflect.Value, h HandlerFunc) Handler
NewReadHandler creates a new Handler instance with the given channel and handler function. The channel is used to receive events, and the handler function is called to handle each event.
type HandlerFunc ¶
HandlerFunc is a function type that represents a handler for events in the event loop. It takes two parameters: `value` of type `reflect.Value` which represents the event value, and `closed` of type `bool` which indicates whether the event loop is closed.
type Loop ¶
type Loop struct {
// contains filtered or unexported fields
}
Loop represents an event loop that handles events using registered handlers.
func (*Loop) Add ¶
Add adds one or more event handlers to the event loop. The event handlers will be executed when the event loop is triggered. It is safe to call this method concurrently from multiple goroutines. The order in which the event handlers are added is preserved. The event loop will wake up after the handlers are added.
func (*Loop) Remove ¶
Remove removes the specified handlers from the event loop. It takes one or more handlers as arguments and removes them by their channels. The channels of the handlers are collected into a slice and passed to the RemoveByChannels method.
func (*Loop) RemoveByChannels ¶
RemoveByChannels removes the handlers associated with the specified channels from the event loop. The channels are sorted based on their memory addresses before removing the handlers. After removing the handlers, the event loop is woken up to process any pending events.
func (*Loop) Run ¶
func (el *Loop) Run(stop <-chan struct{})
Run starts the event loop and runs until the stop channel is closed. It continuously listens for events on the stop channel and the wake channel. When an event is received on the stop channel, the event loop stops and returns. When an event is received on the wake channel, the event loop continues to the next iteration. The event loop executes the registered handlers based on the received events. If an event handler returns an error, the event loop removes the handler and calls it with a nil value and the error set to true. If an event handler panics, the event loop removes the handler and panics with a descriptive error message.