Documentation ¶
Index ¶
Constants ¶
const EventBufferSize = 16
EventBufferSize is the buffer size of the channel for each subscription.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventService ¶
type EventService struct {
// contains filtered or unexported fields
}
EventService represents a service for managing events in the system.
func NewEventService ¶
func NewEventService() *EventService
NewEventService returns a new instance of EventService.
func (*EventService) PublishEvent ¶
func (s *EventService) PublishEvent(userID int, event wtf.Event)
PublishEvent publishes event to all of a user's subscriptions.
If user's channel is full then the user is disconnected. This is to prevent slow users from blocking progress.
func (*EventService) Subscribe ¶
func (s *EventService) Subscribe(ctx context.Context) (wtf.Subscription, error)
Subscribe creates a new subscription for the currently logged in user. Returns EUNAUTHORIZED if user is not logged in.
func (*EventService) Unsubscribe ¶
func (s *EventService) Unsubscribe(sub *Subscription)
Unsubscribe disconnects sub from the service.
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription represents a stream of user-related events.
func (*Subscription) C ¶
func (s *Subscription) C() <-chan wtf.Event
C returns a receive-only channel of user-related events.
func (*Subscription) Close ¶
func (s *Subscription) Close() error
Close disconnects the subscription from the service it was created from.