Use resettable sync.Once instead of reassignment
This commit is contained in:
parent
51e04c9d0f
commit
909ffd1998
7 changed files with 133 additions and 4 deletions
|
@ -6,6 +6,8 @@ import (
|
|||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/khlieng/dispatch/Godeps/_workspace/src/github.com/matryer/resync"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
|
@ -29,7 +31,7 @@ type Client struct {
|
|||
quit chan struct{}
|
||||
reconnect chan struct{}
|
||||
ready sync.WaitGroup
|
||||
once sync.Once
|
||||
once resync.Once
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -107,7 +106,7 @@ func (c *Client) run() {
|
|||
|
||||
case <-c.reconnect:
|
||||
c.reconnect = make(chan struct{})
|
||||
c.once = sync.Once{}
|
||||
c.once.Reset()
|
||||
c.tryConnect()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue