GODT-1366: Simple lookup of index and select current user

This commit is contained in:
Jakub
2021-11-05 12:31:32 +01:00
parent 9984165798
commit 961742fa53
13 changed files with 106 additions and 17 deletions

View File

@ -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`.