From 0b4e48af3b94f287f9b49911c22e6c11af180aa8 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Thu, 19 Jan 2023 12:37:21 +0100 Subject: [PATCH] Remove unnecessary variable to flag closed loopback client. --- natsclient_loopback.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/natsclient_loopback.go b/natsclient_loopback.go index 8c95991..56b6fb6 100644 --- a/natsclient_loopback.go +++ b/natsclient_loopback.go @@ -35,7 +35,6 @@ type LoopbackNatsClient struct { mu sync.Mutex subscriptions map[string]map[*loopbackNatsSubscription]bool - stopping bool wakeup sync.Cond incoming list.List } @@ -53,10 +52,11 @@ func (c *LoopbackNatsClient) processMessages() { c.mu.Lock() defer c.mu.Unlock() for { - for !c.stopping && c.incoming.Len() == 0 { + for c.subscriptions != nil && c.incoming.Len() == 0 { c.wakeup.Wait() } - if c.stopping { + if c.subscriptions == nil { + // Client was closed. break } @@ -91,7 +91,6 @@ func (c *LoopbackNatsClient) Close() { defer c.mu.Unlock() c.subscriptions = nil - c.stopping = true c.incoming.Init() c.wakeup.Signal() }