Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event interface {
// Type is optional.
// Empty values are interpreted by the client as "message" events.
// Non-empty values require a matching event listener on the client.
Type() string
// Data is required. It must conform to UTF-8.
Data() []byte
}
Event is an interface for our core Event type. Implement on your own types to serialize custom events.
type EventServer ¶
type EventServer struct {
// contains filtered or unexported fields
}
EventServer is the event server.
func NewEventServer ¶
func NewEventServer() *EventServer
NewEventServer returns an empty EventServer.
func (*EventServer) Broadcast ¶
func (e *EventServer) Broadcast(name string, event Event) error
Broadcast sends an event to all subscribers of the named topic.
func (*EventServer) ServeHTTP ¶
func (e *EventServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler to serve events.
func (*EventServer) Stats ¶ added in v0.3.0
func (e *EventServer) Stats() Stats
type Stats ¶ added in v0.3.0
type Stats struct {
Topics int
ByTopic map[string]TopicStats
}
type Subscriber ¶
type Subscriber struct {
// contains filtered or unexported fields
}
Subscriber is an individual topic client.
func (Subscriber) Close ¶
func (s Subscriber) Close()
Close closes the subscriber channel, ending WriteEvents' loop.
func (Subscriber) Push ¶
func (s Subscriber) Push(event Event) error
Push enqueues an event for the subscriber.
func (Subscriber) WriteEvents ¶
func (s Subscriber) WriteEvents(w http.ResponseWriter) error
WriteEvents writes headers and streams events to the provided ResponseWriter.
type SubscriberStats ¶ added in v0.3.0
type Topic ¶
type Topic struct {
// contains filtered or unexported fields
}
Topic is a collection of subscribers.
func NewTopic ¶
NewTopic returns a new Topic. The backlog parameter determines how many events are buffered before blocking. The fanout goroutine is started immediately.
func (*Topic) Subscribe ¶
func (t *Topic) Subscribe(sub Subscriber)
Subscribe adds a subscriber to this topic.
func (*Topic) Unsubscribe ¶
func (t *Topic) Unsubscribe(ctx context.Context, sub Subscriber)
Unsubscribe removes a subscriber from this topic when the context is cancelled.
type TopicStats ¶ added in v0.3.0
type TopicStats struct {
Subscribers int
Pending int
Capacity int
BySubscriber map[string]SubscriberStats
}