mirror of
https://github.com/pion/webrtc.git
synced 2025-10-05 15:16:52 +08:00
Avoid leaking tickers
In Go 1.22 and earlier, a ticker needs to be explicitly stopped when it's no longer useful in order to avoid a resource leak. In Go 1.23 and later, an orphaned ticker will eventually be garbage collected, but it's still more thrifty to stop it early.
This commit is contained in:

committed by
Sean DuBois

parent
cbbb1c29e5
commit
f29ef99b22
@@ -113,7 +113,9 @@ func createAnswerer() *webrtc.PeerConnection {
|
||||
since := time.Now()
|
||||
|
||||
// Start printing out the observed throughput
|
||||
for range time.NewTicker(1000 * time.Millisecond).C {
|
||||
ticker := time.NewTicker(1000 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
for range ticker.C {
|
||||
bps := float64(atomic.LoadUint64(&totalBytesReceived)*8) / time.Since(since).Seconds()
|
||||
log.Printf("Throughput: %.03f Mbps", bps/1024/1024)
|
||||
}
|
||||
|
Reference in New Issue
Block a user