nip47_notification_queue.go raw
1 package notifications
2
3 import (
4 "github.com/getAlby/hub/events"
5 "github.com/getAlby/hub/logger"
6 )
7
8 type Nip47NotificationQueue interface {
9 Channel() <-chan *events.Event
10 AddToQueue(event *events.Event)
11 }
12
13 type nip47NotificationQueue struct {
14 channel chan *events.Event
15 }
16
17 /*
18 Queue events that will be consumed when the relay connection is online
19 */
20 func NewNip47NotificationQueue() *nip47NotificationQueue {
21 return &nip47NotificationQueue{
22 channel: make(chan *events.Event, 1000),
23 }
24 }
25
26 func (q *nip47NotificationQueue) AddToQueue(event *events.Event) {
27 select {
28 case q.channel <- event: // Put in the channel unless it is full
29 // successfully sent to channel
30 default:
31 // channel full
32 logger.Logger.WithField("event", event).Error("NIP47NotificationQueue channel full. Discarding value")
33 }
34 }
35
36 func (q *nip47NotificationQueue) Channel() <-chan *events.Event {
37 return q.channel
38 }
39