Skip to content

Commit

Permalink
Made channel methods private
Browse files Browse the repository at this point in the history
  • Loading branch information
meling committed May 10, 2021
1 parent 51a48cb commit f685e26
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
14 changes: 7 additions & 7 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type channel struct {
sendQ chan request
nodeID uint32
mu sync.Mutex
lastErr error
lastError error
latency time.Duration
backoffCfg backoff.Config
rand *rand.Rand
Expand Down Expand Up @@ -212,18 +212,18 @@ func (c *channel) reconnect() {
func (c *channel) setLastErr(err error) {
c.mu.Lock()
defer c.mu.Unlock()
c.lastErr = err
c.lastError = err
}

// LastErr returns the last error encountered (if any) when using this channel.
func (c *channel) LastErr() error {
// lastErr returns the last error encountered (if any) when using this channel.
func (c *channel) lastErr() error {
c.mu.Lock()
defer c.mu.Unlock()
return c.lastErr
return c.lastError
}

// Latency returns the latency between the client and this channel.
func (c *channel) Latency() time.Duration {
// channelLatency returns the latency between the client and this channel.
func (c *channel) channelLatency() time.Duration {
c.mu.Lock()
defer c.mu.Unlock()
return c.latency
Expand Down
6 changes: 3 additions & 3 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ func (n *Node) FullString() string {

// LastErr returns the last error encountered (if any) for this node.
func (n *Node) LastErr() error {
return n.channel.LastErr()
return n.channel.lastErr()
}

// Latency returns the latency between the client and this node.
func (n *Node) Latency() time.Duration {
return n.channel.Latency()
return n.channel.channelLatency()
}

type lessFunc func(n1, n2 *Node) bool
Expand Down Expand Up @@ -220,7 +220,7 @@ var Port = func(n1, n2 *Node) bool {
// LastNodeError sorts nodes by their LastErr() status in increasing order. A
// node with LastErr() != nil is larger than a node with LastErr() == nil.
var LastNodeError = func(n1, n2 *Node) bool {
if n1.channel.LastErr() != nil && n2.channel.LastErr() == nil {
if n1.channel.lastErr() != nil && n2.channel.lastErr() == nil {
return false
}
return true
Expand Down
16 changes: 8 additions & 8 deletions node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ func TestNodeSort(t *testing.T) {
{
id: 100,
channel: &channel{
lastErr: nil,
latency: time.Second,
lastError: nil,
latency: time.Second,
},
},
{
id: 101,
channel: &channel{
lastErr: errors.New("some error"),
latency: 250 * time.Millisecond,
lastError: errors.New("some error"),
latency: 250 * time.Millisecond,
},
},
{
id: 42,
channel: &channel{
lastErr: nil,
latency: 300 * time.Millisecond,
lastError: nil,
latency: 300 * time.Millisecond,
},
},
{
id: 99,
channel: &channel{
lastErr: errors.New("some error"),
latency: 500 * time.Millisecond,
lastError: errors.New("some error"),
latency: 500 * time.Millisecond,
},
},
}
Expand Down

0 comments on commit f685e26

Please sign in to comment.