github.com/Axway/agent-sdk@v1.1.101/pkg/notification/subscriber.go (about) 1 package notification 2 3 // Subscriber - subscribes to a notifier 4 type Subscriber interface { 5 GetID() string 6 SendMsg(interface{}) 7 Close() // Unsubscribes and closes channel 8 close() // closes channel 9 } 10 11 type notifierSubscriber struct { 12 Subscriber 13 id string 14 notifier string 15 output chan interface{} 16 } 17 18 // GetID - return the id of this subscriber 19 func (s *notifierSubscriber) GetID() string { 20 return s.id 21 } 22 23 // SendMsg - the notifier calls this on the subscriber to send data 24 func (s *notifierSubscriber) SendMsg(data interface{}) { 25 select { 26 case <-s.output: 27 default: 28 s.output <- data 29 } 30 } 31 32 // Close - used to unsubscribe this Subscriber from its notifier and close the channel 33 func (s *notifierSubscriber) Close() { 34 Unsubscribe(s.notifier, s.id) 35 } 36 37 // Close - used to unsubscribe this Subscriber from its notifier and close the channel 38 func (s *notifierSubscriber) close() { 39 // Close the channel 40 close(s.output) 41 }