Skip to content

Commit 2b9d0ed

Browse files
authored
a bit cleaner run handler code (#114)
1 parent 989f6e9 commit 2b9d0ed

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

client.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -770,29 +770,29 @@ func (c *Client) reader(t transport, disconnectCh chan struct{}) {
770770

771771
func (c *Client) runHandlerSync(fn func()) {
772772
c.mu.RLock()
773-
if c.cbQueue == nil {
774-
c.mu.RUnlock()
773+
queue := c.cbQueue
774+
c.mu.RUnlock()
775+
if queue == nil {
775776
return
776777
}
777778
waitCh := make(chan struct{})
778-
c.cbQueue.push(func(delay time.Duration) {
779+
queue.push(func(delay time.Duration) {
779780
defer close(waitCh)
780781
fn()
781782
})
782-
c.mu.RUnlock()
783783
<-waitCh
784784
}
785785

786786
func (c *Client) runHandlerAsync(fn func()) {
787787
c.mu.RLock()
788-
if c.cbQueue == nil {
789-
c.mu.RUnlock()
788+
queue := c.cbQueue
789+
c.mu.RUnlock()
790+
if queue == nil {
790791
return
791792
}
792-
c.cbQueue.push(func(delay time.Duration) {
793+
queue.push(func(delay time.Duration) {
793794
fn()
794795
})
795-
c.mu.RUnlock()
796796
}
797797

798798
func (c *Client) handle(reply *protocol.Reply) {

0 commit comments

Comments
 (0)