-
Notifications
You must be signed in to change notification settings - Fork 27
/
event.go
49 lines (40 loc) · 1014 Bytes
/
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
45
46
47
48
49
// Package event mediates notification between controllers and recorder
package event
// Action represents the kind of object change we're notifying
type Action int
const (
// Delete is the object deletion Action
Delete Action = iota
// Upsert is the update or create Action
Upsert
)
// Notification conveys an object delete/upsert notification
type Notification struct {
Action Action
Key string
Kind string
Object []byte
}
// Notifier mediates notifications between controllers and recorder
type Notifier interface {
Send(notif *Notification)
ReadChan() <-chan Notification
}
// Unbuffered implements Notifier
type Unbuffered struct {
c chan Notification
}
// New creates an Unbuffered
func New() *Unbuffered {
return &Unbuffered{
c: make(chan Notification),
}
}
// Send sends a notification
func (n *Unbuffered) Send(notif *Notification) {
n.c <- *notif
}
// ReadChan returns a channel to read Notifications from
func (n *Unbuffered) ReadChan() <-chan Notification {
return n.c
}