Skip to content

Commit

Permalink
Tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
evanlinjin committed May 24, 2020
1 parent c1f3fca commit a24178b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/app/appevent/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ func NewSubscriber() *Subscriber {
}

// TCPDial subscribes to the TCPDial event channel.
// This should only be called once.
func (s *Subscriber) TCPDial(action func(data TCPDialData)) {
s.mx.Lock()
defer s.mx.Unlock()

ch := make(chan *Event, s.chanSize)
s.m[TCPDial] = ch
s.mx.Unlock()

go func() {
for ev := range ch {
Expand All @@ -50,12 +50,12 @@ func (s *Subscriber) TCPDial(action func(data TCPDialData)) {
}

// TCPClose subscribes to the TCPClose event channel.
// This should only be called once.
func (s *Subscriber) TCPClose(action func(data TCPCloseData)) {
s.mx.Lock()
defer s.mx.Unlock()

ch := make(chan *Event, s.chanSize)
s.m[TCPClose] = ch
s.mx.Unlock()

go func() {
for ev := range ch {
Expand All @@ -70,12 +70,12 @@ func (s *Subscriber) TCPClose(action func(data TCPCloseData)) {
// Subscriptions returns a map of all subscribed event types.
func (s *Subscriber) Subscriptions() map[string]bool {
s.mx.RLock()
defer s.mx.RUnlock()

subs := make(map[string]bool, len(s.m))
for t := range s.m {
subs[t] = true
}
s.mx.RUnlock()

return subs
}

Expand Down

0 comments on commit a24178b

Please sign in to comment.