-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqueuedEvent.go
90 lines (72 loc) · 1.55 KB
/
queuedEvent.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package sentry
// A QueuedEvent allows you to track the status of sending
// an event to Sentry.
type QueuedEvent interface {
EventID() string
Wait() QueuedEvent
WaitChannel() <-chan error
Error() error
}
// QueuedEventInternal is an interface used by SendQueue
// implementations to "complete" a queued event once it has
// either been sent to Sentry, or sending failed with an error.
type QueuedEventInternal interface {
QueuedEvent
Packet() Packet
Config() Config
Complete(err error)
}
// NewQueuedEvent is used by SendQueue implementations to expose
// information about the events that they are sending to Sentry.
func NewQueuedEvent(cfg Config, packet Packet) QueuedEvent {
e := &queuedEvent{
cfg: cfg,
packet: packet,
wait: make(chan struct{}),
}
return e
}
type queuedEvent struct {
cfg Config
packet Packet
err error
wait chan struct{}
}
func (e *queuedEvent) EventID() string {
if packet, ok := e.packet.(*packet); ok {
return packet.getEventID()
}
return ""
}
func (e *queuedEvent) Wait() QueuedEvent {
_, _ = <-e.wait
return e
}
func (e *queuedEvent) WaitChannel() <-chan error {
ch := make(chan error)
go func() {
_, _ = <-e.wait
if e.err != nil {
ch <- e.err
}
close(ch)
}()
return ch
}
func (e *queuedEvent) Error() error {
return e.Wait().(*queuedEvent).err
}
func (e *queuedEvent) Packet() Packet {
return e.packet
}
func (e *queuedEvent) Config() Config {
return e.cfg
}
func (e *queuedEvent) Complete(err error) {
select {
case _, _ = <-e.wait:
default:
e.err = err
close(e.wait)
}
}