Skip to content
Snippets Groups Projects

Add method which allows to remove a receiver

Merged Malte Bauch requested to merge timeout-key-forwarding-fix into master
2 files
+ 20
1
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -5,6 +5,7 @@ import (
@@ -5,6 +5,7 @@ import (
"sync"
"sync"
"github.com/google/uuid"
"github.com/google/uuid"
 
"github.com/sirupsen/logrus"
)
)
type Receiver struct {
type Receiver struct {
@@ -22,12 +23,27 @@ func (r *Receiver) RequestReceiverChannel(pathId uuid.UUID) (<-chan struct{}, er
@@ -22,12 +23,27 @@ func (r *Receiver) RequestReceiverChannel(pathId uuid.UUID) (<-chan struct{}, er
return newSubChan, nil
return newSubChan, nil
}
}
 
func (r *Receiver) RemoveReceiver(pathId uuid.UUID) error {
 
r.mu.Lock()
 
defer r.mu.Unlock()
 
 
if channel, ok := r.receivers[pathId]; ok {
 
close(channel)
 
delete(r.receivers, pathId)
 
} else {
 
return fmt.Errorf("There are no active subscribers for pathId: %s", pathId)
 
}
 
 
logrus.Debugf("Current active receivers after removing receiver for pathId: %s; Receivers: %v", pathId, r.receivers)
 
return nil
 
}
 
func (r *Receiver) InformReceiver(pathId uuid.UUID) error {
func (r *Receiver) InformReceiver(pathId uuid.UUID) error {
r.mu.RLock()
r.mu.RLock()
defer r.mu.RUnlock()
defer r.mu.RUnlock()
if receiver, ok := r.receivers[pathId]; ok {
if receiver, ok := r.receivers[pathId]; ok {
receiver <- struct{}{}
go func() { receiver <- struct{}{} }()
} else {
} else {
return fmt.Errorf("There are no active subscribers for pathId: %s", pathId)
return fmt.Errorf("There are no active subscribers for pathId: %s", pathId)
}
}
Loading