lib/stun: Inline util.OnDone, comment on its purpose (#7308)
Co-authored-by: greatroar <@>
This commit is contained in:
co-authored by
greatroar <@>
parent
e19d6e993d
commit
8b86171642
+6
-1
@@ -111,7 +111,12 @@ func (s *Service) Serve(ctx context.Context) error {
|
|||||||
s.setExternalAddress(nil, "")
|
s.setExternalAddress(nil, "")
|
||||||
}()
|
}()
|
||||||
|
|
||||||
util.OnDone(ctx, func() { _ = s.stunConn.Close() })
|
// Closing s.stunConn unblocks operations that use the connection
|
||||||
|
// (Discover, Keepalive) and might otherwise block us from returning.
|
||||||
|
go func() {
|
||||||
|
<-ctx.Done()
|
||||||
|
_ = s.stunConn.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
timer := time.NewTimer(time.Millisecond)
|
timer := time.NewTimer(time.Millisecond)
|
||||||
|
|
||||||
|
|||||||
@@ -250,14 +250,6 @@ func AddressUnspecifiedLess(a, b net.Addr) bool {
|
|||||||
return aIsUnspecified
|
return aIsUnspecified
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnDone calls fn when ctx is cancelled.
|
|
||||||
func OnDone(ctx context.Context, fn func()) {
|
|
||||||
go func() {
|
|
||||||
<-ctx.Done()
|
|
||||||
fn()
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func CallWithContext(ctx context.Context, fn func() error) error {
|
func CallWithContext(ctx context.Context, fn func() error) error {
|
||||||
var err error
|
var err error
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|||||||
Reference in New Issue
Block a user