Documentation
¶
Index ¶
- type Event
- func (e *Event) Done(result interface{}, err error)
- func (e *Event) GetContext() context.Context
- func (e *Event) GetDeadline() time.Time
- func (e *Event) GetID() uint64
- func (e *Event) GetTimestamp() time.Time
- func (e *Event) GetType() string
- func (e *Event) HasDeadline() bool
- func (e *Event) IsExpired() bool
- func (e *Event) Wait() (interface{}, error)
- type EventContext
- type EventHandlerFunc
- type EventOption
- type EventQueue
- type EventQueueConfig
- type IEvent
- type IEventHandler
- type IEventQueue
- type ProcessingMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event is the default implementation of IEvent
func NewEvent ¶
func NewEvent(eventType string, ctx context.Context, options ...EventOption) *Event
NewEvent creates a new event instance with auto-incrementing ID
func (*Event) GetContext ¶
GetContext returns the event context
func (*Event) GetDeadline ¶
GetDeadline returns the deadline for processing this event
func (*Event) GetTimestamp ¶
GetTimestamp returns when the event was created
func (*Event) HasDeadline ¶
HasDeadline returns true if the event has a deadline
type EventContext ¶
type EventContext struct {
// contains filtered or unexported fields
}
EventContext holds the context data and completion channel for an event
func NewEventContext ¶
func NewEventContext(ctx context.Context) *EventContext
NewEventContext creates a new event context
func (*EventContext) Context ¶
func (ec *EventContext) Context() context.Context
Context returns the underlying context
func (*EventContext) Done ¶
func (ec *EventContext) Done(result interface{}, err error)
Done signals completion with result
func (*EventContext) Wait ¶
func (ec *EventContext) Wait() (interface{}, error)
Wait waits for completion and returns the result
type EventHandlerFunc ¶
EventHandlerFunc is a function type that implements IEventHandler
type EventOption ¶
type EventOption func(*Event)
EventOption is a function that configures an Event
func WithDeadline ¶
func WithDeadline(deadline time.Time) EventOption
WithDeadline sets a deadline for the event
func WithTimeout ¶
func WithTimeout(timeout time.Duration) EventOption
WithTimeout sets a timeout duration for the event from creation time
type EventQueue ¶
type EventQueue struct {
// contains filtered or unexported fields
}
EventQueue is the default implementation of IEventQueue Uses lock-free design for sequential processing
func NewDefaultEventQueue ¶
func NewDefaultEventQueue() *EventQueue
NewDefaultEventQueue creates a new event queue with default configuration: - BufferSize: 1000 - ProcessingMode: Sequential
func NewEventQueue ¶
func NewEventQueue(config EventQueueConfig) *EventQueue
NewEventQueue creates a new event queue with the given configuration
func (*EventQueue) Enqueue ¶
func (eq *EventQueue) Enqueue(event IEvent) error
Enqueue adds an event to the queue
func (*EventQueue) GetQueueSize ¶
func (eq *EventQueue) GetQueueSize() int
GetQueueSize returns the current number of events in the queue
func (*EventQueue) RegisterHandler ¶
func (eq *EventQueue) RegisterHandler(eventType string, handler IEventHandler)
RegisterHandler registers a handler for a specific event type Only one handler per event type is allowed. Registering a new handler will replace the existing one. Note: Should be called before Start() to avoid race conditions
func (*EventQueue) Start ¶
func (eq *EventQueue) Start(ctx context.Context) error
Start begins processing events from the queue
func (*EventQueue) Stop ¶
func (eq *EventQueue) Stop() error
Stop gracefully stops the queue processing
type EventQueueConfig ¶
type EventQueueConfig struct {
BufferSize int
ProcessingMode ProcessingMode
}
EventQueueConfig holds configuration for creating an event queue
type IEvent ¶
type IEvent interface {
// GetID returns the unique identifier of the event
GetID() uint64
// GetType returns the type/category of the event
GetType() string
// GetContext returns the event context
GetContext() context.Context
// GetTimestamp returns when the event was created
GetTimestamp() time.Time
// GetDeadline returns the deadline for processing this event
// Returns zero time if no deadline is set
GetDeadline() time.Time
// HasDeadline returns true if the event has a deadline
HasDeadline() bool
// IsExpired checks if the event has passed its deadline
IsExpired() bool
// Done signals that the event processing is complete and sets the result
Done(result interface{}, err error)
// Wait waits for the event to be processed and returns the result
Wait() (interface{}, error)
}
IEvent represents a basic event interface that can be queued and processed
type IEventHandler ¶
type IEventHandler interface {
// Handle processes the event and returns an error if processing fails
Handle(ctx context.Context, event IEvent) error
}
IEventHandler defines the interface for processing events
type IEventQueue ¶
type IEventQueue interface {
// Enqueue adds an event to the queue
Enqueue(event IEvent) error
// Start begins processing events from the queue
Start(ctx context.Context) error
// Stop gracefully stops the queue processing
Stop() error
// RegisterHandler registers a handler for a specific event type
RegisterHandler(eventType string, handler IEventHandler)
// GetQueueSize returns the current number of events in the queue
GetQueueSize() int
}
IEventQueue defines the interface for an event queue
type ProcessingMode ¶
type ProcessingMode int
ProcessingMode defines how events should be processed
const ( // Sequential mode processes events one at a time in order Sequential ProcessingMode = iota // Parallel mode processes events concurrently Parallel )
func (ProcessingMode) String ¶ added in v1.0.2
func (pm ProcessingMode) String() string
String returns the string representation of ProcessingMode