Skip to content

Commit

Permalink
prevent a subscriber from blocking all others
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Aug 18, 2023
1 parent c3c2995 commit 401c29a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion publisher_sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
"github.com/bluenviron/goroslib/v2/pkg/prototcp"
)

const (
writeBufferSize = 16
)

type publisherSubscriber struct {
pub *Publisher
callerID string
Expand Down Expand Up @@ -40,7 +44,7 @@ func newPublisherSubscriber(
udpAddr: udpAddr,
ctx: ctx,
ctxCancel: ctxCancel,
chWriteMessage: make(chan interface{}),
chWriteMessage: make(chan interface{}, writeBufferSize),
}

pub.subscribersWg.Add(1)
Expand Down Expand Up @@ -197,5 +201,6 @@ func (ps *publisherSubscriber) writeMessage(msg interface{}) {
select {
case ps.chWriteMessage <- msg:
case <-ps.ctx.Done():
default: // buffer is full

Check warning on line 204 in publisher_sub.go

View check run for this annotation

Codecov / codecov/patch

publisher_sub.go#L204

Added line #L204 was not covered by tests
}
}

0 comments on commit 401c29a

Please sign in to comment.