Documentation
¶
Index ¶
- Constants
- type Event
- type EventLoop
- func (el *EventLoop) IsCatchingUp() bool
- func (el *EventLoop) IsPaused() bool
- func (el *EventLoop) Pause()
- func (el *EventLoop) ScheduleEvent(timestamp int64, duration int64, handlername string, payload any) error
- func (el *EventLoop) Start()
- func (el *EventLoop) Stop()
- func (el *EventLoop) Unpause()
- type IEventRegistry
- type LogConfig
- type RotatingFileWriter
Constants ¶
const ( // DefaultMaxBytes is the default maximum size of log file before rotation (10MB) DefaultMaxBytes = 10 * 1024 * 1024 // 10 megabytes )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
Timestamp int64 `json:"timestamp"`
Duration int64 `json:"duration"`
Payload interface{} `json:"payload"`
Handler string `json:"handler"`
// contains filtered or unexported fields
}
Event represents a scheduled event with a handler function
func (Event) Addhandler ¶
type EventLoop ¶
type EventLoop struct {
// contains filtered or unexported fields
}
EventLoop manages the event scheduling and execution
func NewEventLoop ¶
func NewEventLoop(tickInterval time.Duration, registry IEventRegistry, logConfig *LogConfig) *EventLoop
NewEventLoop creates a new event loop with the specified tick interval logConfig is optional - pass nil to disable logging
func (*EventLoop) IsCatchingUp ¶
IsCatchingUp returns whether the loop is currently in catch-up mode
func (*EventLoop) Pause ¶
func (el *EventLoop) Pause()
Pause pauses the event loop, preventing event scheduling and processing
func (*EventLoop) ScheduleEvent ¶
func (el *EventLoop) ScheduleEvent(timestamp int64, duration int64, handlername string, payload any) error
ScheduleEvent schedules an event to be executed at the specified timestamp This will block during catch-up mode until all past events are processed Events cannot be scheduled when the loop is paused
type IEventRegistry ¶
Registry of event handlers. It allows you to retrieve events by name.
type LogConfig ¶ added in v2.0.4
type LogConfig struct {
Enabled bool // Whether logging is enabled
FilePath string // Path to the log file
IncludeInfo bool // Whether to include INFO level logs (ERROR always logged when enabled)
}
LogConfig holds configuration for event loop logging
type RotatingFileWriter ¶ added in v2.0.4
type RotatingFileWriter struct {
// contains filtered or unexported fields
}
RotatingFileWriter implements io.Writer with automatic file rotation when the file size exceeds a maximum threshold
func NewRotatingFileWriter ¶ added in v2.0.4
func NewRotatingFileWriter(filepath string, maxBytes int64) (*RotatingFileWriter, error)
NewRotatingFileWriter creates a new rotating file writer
func (*RotatingFileWriter) Close ¶ added in v2.0.4
func (rfw *RotatingFileWriter) Close() error
Close closes the underlying file