mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-24 10:56:43 +00:00
GODT-1366: Simple lookup of index and select current user
This commit is contained in:
@ -35,6 +35,7 @@ type Listener interface {
|
||||
Emit(eventName string, data string)
|
||||
SetBuffer(eventName string)
|
||||
RetryEmit(eventName string)
|
||||
Book(eventName string)
|
||||
}
|
||||
|
||||
type listener struct {
|
||||
@ -56,6 +57,19 @@ func New() Listener {
|
||||
}
|
||||
}
|
||||
|
||||
// Book wil create the list of channels for specific eventName. This should be
|
||||
// used when there is not always listening channel available and it should not
|
||||
// be logged when no channel is awaiting an emitted event.
|
||||
func (l *listener) Book(eventName string) {
|
||||
if l.channels == nil {
|
||||
l.channels = make(map[string][]chan<- string)
|
||||
}
|
||||
if _, ok := l.channels[eventName]; !ok {
|
||||
l.channels[eventName] = []chan<- string{}
|
||||
}
|
||||
log.WithField("name", eventName).Debug("Channel booked")
|
||||
}
|
||||
|
||||
// SetLimit sets the limit for the `eventName`. When the same event (name and data)
|
||||
// is emitted within last time duration (`limit`), event is dropped. Zero limit clears
|
||||
// the limit for the specific `eventName`.
|
||||
|
||||
@ -59,6 +59,9 @@ func TestAddAndRemove(t *testing.T) {
|
||||
|
||||
channel := make(chan string)
|
||||
listener.Add("event", channel)
|
||||
listener.Emit("event", "hello!")
|
||||
checkChannelEmitted(t, channel, "hello!")
|
||||
|
||||
listener.Remove("event", channel)
|
||||
listener.Emit("event", "hello!")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user