mirror of
https://github.com/pion/webrtc.git
synced 2025-10-06 07:37:10 +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
@@ -89,7 +89,8 @@ func main() {
|
||||
// * avoids accumulating skew, just calling time.Sleep didn't compensate for the time spent parsing the data
|
||||
// * works around latency issues with Sleep (see https://github.com/golang/go/issues/44343)
|
||||
ticker := time.NewTicker(time.Millisecond * time.Duration((float32(header.TimebaseNumerator)/float32(header.TimebaseDenominator))*1000))
|
||||
for ; true; <-ticker.C {
|
||||
defer ticker.Stop()
|
||||
for range ticker.C {
|
||||
frame, _, ivfErr := ivf.ParseNextFrame()
|
||||
if errors.Is(ivfErr, io.EOF) {
|
||||
fmt.Printf("All frames parsed and sent")
|
||||
|
Reference in New Issue
Block a user