/
event.go
44 lines (33 loc) · 1.31 KB
/
event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package event
import (
"context"
goapackage "github.com/artefactual-sdps/enduro/internal/api/gen/package_"
)
const (
// EventBufferSize is the buffer size of the channel for each subscription.
EventBufferSize = 16
)
// EventService represents a service for managing event dispatch and event
// listeners (aka subscriptions).
type EventService interface {
// Publishes an event to a user's event listeners.
// If the user is not currently subscribed then this is a no-op.
PublishEvent(ctx context.Context, event *goapackage.MonitorEvent)
// Creates a subscription. Caller must call Subscription.Close() when done
// with the subscription.
Subscribe(ctx context.Context) (Subscription, error)
}
// NopEventService returns an event service that does nothing.
func NopEventService() EventService { return &nopEventService{} }
type nopEventService struct{}
func (*nopEventService) PublishEvent(ctx context.Context, event *goapackage.MonitorEvent) {}
func (*nopEventService) Subscribe(ctx context.Context) (Subscription, error) {
panic("not implemented")
}
// Subscription represents a stream of events for a single user.
type Subscription interface {
// Event stream for all user's event.
C() <-chan *goapackage.MonitorEvent
// Closes the event stream channel and disconnects from the event service.
Close() error
}