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
@@ -183,7 +183,9 @@ func handleOnOpen(channel *webrtc.DataChannel) func() {
|
||||
return func() {
|
||||
fmt.Printf("Data channel '%s'-'%d' open. Random messages will now be sent to any connected DataChannels every 5 seconds\n", channel.Label(), channel.ID())
|
||||
|
||||
for range time.NewTicker(5 * time.Second).C {
|
||||
ticker := time.NewTicker(5 * time.Second)
|
||||
defer ticker.Stop()
|
||||
for range ticker.C {
|
||||
message, err := randutil.GenerateCryptoRandomString(15, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
Reference in New Issue
Block a user