Skip to content

Commit

Permalink
client: implement NumPendingWrites() for Client
Browse files Browse the repository at this point in the history
  • Loading branch information
lithdew committed Jun 10, 2020
1 parent 846e745 commit bf6b63d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (c *Client) SendNoWait(buf []byte) error {

func (c *Client) Request(dst, buf []byte) ([]byte, error) {
c.once.Do(c.init)

cc := c.getClientConn()

<-cc.ready
Expand All @@ -85,13 +86,23 @@ func (c *Client) Request(dst, buf []byte) ([]byte, error) {
return cc.conn.Request(dst, buf)
}

func (c *Client) NumPendingWrites() int {
c.mu.Lock()
defer c.mu.Unlock()

n := 0
for _, cc := range c.conns {
n += cc.conn.NumPendingWrites()
}
return n
}

func (c *Client) Shutdown() {
c.once.Do(c.init)

shutdown := func() {
c.shutdown.Do(func() {
close(c.done)
}
c.shutdown.Do(shutdown)
})
}

func (c *Client) init() {
Expand Down

0 comments on commit bf6b63d

Please sign in to comment.