Don't allocate new error inside TaskLoop

Libraries use errors.Is to catch this error. Allocating a new one inside
internal breaks that
This commit is contained in:
Sean DuBois
2024-07-25 11:18:50 -04:00
parent f15ba9868c
commit abf50f9c34
2 changed files with 10 additions and 6 deletions

View File

@@ -13,8 +13,8 @@ import (
atomicx "github.com/pion/ice/v3/internal/atomic"
)
// errClosed indicates that the loop has been stopped
var errClosed = errors.New("the agent is closed")
// ErrClosed indicates that the loop has been stopped
var ErrClosed = errors.New("the agent is closed")
type task struct {
fn func(context.Context)
@@ -68,7 +68,7 @@ func (l *Loop) Close() error {
return err
}
l.err.Store(errClosed)
l.err.Store(ErrClosed)
close(l.done)
<-l.taskLoopDone
@@ -104,7 +104,7 @@ func (l *Loop) Done() <-chan struct{} {
func (l *Loop) Err() error {
select {
case <-l.done:
return errClosed
return ErrClosed
default:
return nil
}