Remove some unnecessary locks
This commit is contained in:
bovenliggende
b79f4c8f6d
commit
0fe8b66ff7
|
@ -191,9 +191,6 @@ func NewSubscriber(client *Client, topic string, index int64, handler msgbus.Han
|
|||
}
|
||||
|
||||
func (s *Subscriber) url() string {
|
||||
s.RLock()
|
||||
defer s.RUnlock()
|
||||
|
||||
u, err := url.Parse(s.client.url)
|
||||
if err != nil {
|
||||
log.Fatalf("invalid url: %s", s.client.url)
|
||||
|
@ -225,14 +222,12 @@ func (s *Subscriber) maybeUpdateIndex(msg *msgbus.Message) {
|
|||
}
|
||||
|
||||
func (s *Subscriber) connect(ctx context.Context) (*websocket.Conn, error) {
|
||||
s.RLock()
|
||||
b := &backoff.Backoff{
|
||||
Min: s.reconnectInterval,
|
||||
Max: s.maxReconnectInterval,
|
||||
Factor: 2,
|
||||
Jitter: true,
|
||||
}
|
||||
s.RUnlock()
|
||||
|
||||
for {
|
||||
url := s.url()
|
||||
|
@ -254,6 +249,7 @@ func (s *Subscriber) connect(ctx context.Context) (*websocket.Conn, error) {
|
|||
// never reached
|
||||
}
|
||||
|
||||
// Run runs the subscriber client with the provided context
|
||||
func (s *Subscriber) Run(ctx context.Context) error {
|
||||
conn, err := s.connect(ctx)
|
||||
if err != nil {
|
||||
|
@ -286,10 +282,7 @@ func (s *Subscriber) Run(ctx context.Context) error {
|
|||
}
|
||||
|
||||
func (s *Subscriber) writeloop(ctx context.Context, conn *websocket.Conn) {
|
||||
s.RLock()
|
||||
t := time.NewTicker(s.pingInterval)
|
||||
s.RUnlock()
|
||||
|
||||
defer t.Stop()
|
||||
|
||||
for {
|
||||
|
|
Laden…
Verwijs in nieuw issue