interface.go
interface.go - Overview
This file defines the IOMultiplexer
interface, which provides a generic abstraction for platform-specific I/O multiplexer implementations.
Detailed Documentation
IOMultiplexer interface
The IOMultiplexer
interface defines methods for subscribing to events, polling for triggered events, and closing the multiplexer.
Subscribe
Subscribe(event Event) error
Purpose: Subscribes to the given event. When the event is triggered, the Poll
method will return it.
Parameters:
event
(Event): The event to subscribe to. Returns:error
: An error if the subscription fails,nil
otherwise.
Poll
Poll(timeout time.Duration) ([]Event, error)
Purpose: Polls for all the subscribed events simultaneously and returns all the events that were triggered. It blocks until at least one event is triggered or the timeout is reached. Parameters:
timeout
(time.Duration): The maximum time to wait for an event to be triggered. Returns:[]Event
: A slice of events that were triggered.error
: An error if polling fails,nil
otherwise.
Close
Close() error
Purpose: Closes the IOMultiplexer
instance, releasing any associated resources.
Returns:
error
: An error if closing fails,nil
otherwise.