lib/api, lib/model: Fixes around event request tracking (#6774)

This commit is contained in:
Simon Frei
2020-06-25 21:48:48 +02:00
committed by GitHub
parent 80ada1bb6c
commit 4f06708330
4 changed files with 22 additions and 3 deletions
+14
View File
@@ -238,6 +238,7 @@ type Event struct {
type Subscription interface {
C() <-chan Event
Poll(timeout time.Duration) (Event, error)
Mask() EventType
Unsubscribe()
}
@@ -432,6 +433,10 @@ func (s *subscription) C() <-chan Event {
return s.events
}
func (s *subscription) Mask() EventType {
return s.mask
}
func (s *subscription) Unsubscribe() {
select {
case s.toUnsubscribe <- s:
@@ -450,6 +455,7 @@ type bufferedSubscription struct {
type BufferedSubscription interface {
Since(id int, into []Event, timeout time.Duration) []Event
Mask() EventType
}
func NewBufferedSubscription(s Subscription, size int) BufferedSubscription {
@@ -505,6 +511,10 @@ func (s *bufferedSubscription) Since(id int, into []Event, timeout time.Duration
return into
}
func (s *bufferedSubscription) Mask() EventType {
return s.sub.Mask()
}
// Error returns a string pointer suitable for JSON marshalling errors. It
// retains the "null on success" semantics, but ensures the error result is a
// string regardless of the underlying concrete error type.
@@ -540,4 +550,8 @@ func (*noopSubscription) Poll(timeout time.Duration) (Event, error) {
return Event{}, errNoop
}
func (s *noopSubscription) Mask() EventType {
return 0
}
func (*noopSubscription) Unsubscribe() {}