commit 3520f4e8b96e05dfb30874ec2174457684269db6
Author: David Fifield <david(a)bamsoftware.com>
Date: Thu Apr 23 18:14:27 2020 -0600
Simplify Peers.Pop.
---
client/lib/peers.go | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/client/lib/peers.go b/client/lib/peers.go
index f70905e..2649638 100644
--- a/client/lib/peers.go
+++ b/client/lib/peers.go
@@ -62,24 +62,24 @@ func (p *Peers) Collect() (Snowflake, error) {
return connection, nil
}
-// As part of |SnowflakeCollector| interface.
+// Pop blocks until an available, valid snowflake appears. Returns nil after End
+// has been called.
+//
+// Part of |SnowflakeCollector| interface.
func (p *Peers) Pop() Snowflake {
- // Blocks until an available, valid snowflake appears.
- var snowflake Snowflake
- var ok bool
- for snowflake == nil {
- snowflake, ok = <-p.snowflakeChan
+ for {
+ snowflake, ok := <-p.snowflakeChan
if !ok {
return nil
}
conn := snowflake.(*WebRTCPeer)
if conn.closed {
- snowflake = nil
+ continue
}
+ // Set to use the same rate-limited traffic logger to keep consistency.
+ conn.BytesLogger = p.BytesLogger
+ return conn
}
- // Set to use the same rate-limited traffic logger to keep consistency.
- snowflake.(*WebRTCPeer).BytesLogger = p.BytesLogger
- return snowflake
}
// As part of |SnowflakeCollector| interface.