Skip to content

Commit f49dff1

Browse files
committed
internal/mux: replace SetFinalizer with AddCleanup
1 parent fcf6253 commit f49dff1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

internal/mux/mux.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ func (m *Mux) ReadFloat32s(buf []float32) {
156156
}
157157

158158
type Player struct {
159-
p *playerImpl
159+
p *playerImpl
160+
cleanup runtime.Cleanup
160161
}
161162

162163
type playerState int
@@ -191,7 +192,9 @@ func (m *Mux) NewPlayer(src io.Reader) *Player {
191192
bufferSize: m.defaultBufferSize(),
192193
},
193194
}
194-
runtime.SetFinalizer(pl, (*Player).Close)
195+
pl.cleanup = runtime.AddCleanup(pl, func(p *playerImpl) {
196+
_ = p.Close()
197+
}, pl.p)
195198
return pl
196199
}
197200

@@ -432,7 +435,7 @@ func (p *playerImpl) BufferedSize() int {
432435
}
433436

434437
func (p *Player) Close() error {
435-
runtime.SetFinalizer(p, nil)
438+
p.cleanup.Stop()
436439
return p.p.Close()
437440
}
438441

0 commit comments

Comments
 (0)