mirror of
https://github.com/pion/ice.git
synced 2025-10-05 07:26:55 +08:00
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:
@@ -3,7 +3,11 @@
|
|||||||
|
|
||||||
package ice
|
package ice
|
||||||
|
|
||||||
import "errors"
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/pion/ice/v3/internal/taskloop"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrUnknownType indicates an error with Unknown info.
|
// ErrUnknownType indicates an error with Unknown info.
|
||||||
@@ -36,7 +40,7 @@ var (
|
|||||||
ErrProtoType = errors.New("invalid transport protocol type")
|
ErrProtoType = errors.New("invalid transport protocol type")
|
||||||
|
|
||||||
// ErrClosed indicates the agent is closed
|
// ErrClosed indicates the agent is closed
|
||||||
ErrClosed = errors.New("the agent is closed")
|
ErrClosed = taskloop.ErrClosed
|
||||||
|
|
||||||
// ErrNoCandidatePairs indicates agent does not have a valid candidate pair
|
// ErrNoCandidatePairs indicates agent does not have a valid candidate pair
|
||||||
ErrNoCandidatePairs = errors.New("no candidate pairs available")
|
ErrNoCandidatePairs = errors.New("no candidate pairs available")
|
||||||
|
@@ -13,8 +13,8 @@ import (
|
|||||||
atomicx "github.com/pion/ice/v3/internal/atomic"
|
atomicx "github.com/pion/ice/v3/internal/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
// errClosed indicates that the loop has been stopped
|
// ErrClosed indicates that the loop has been stopped
|
||||||
var errClosed = errors.New("the agent is closed")
|
var ErrClosed = errors.New("the agent is closed")
|
||||||
|
|
||||||
type task struct {
|
type task struct {
|
||||||
fn func(context.Context)
|
fn func(context.Context)
|
||||||
@@ -68,7 +68,7 @@ func (l *Loop) Close() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
l.err.Store(errClosed)
|
l.err.Store(ErrClosed)
|
||||||
|
|
||||||
close(l.done)
|
close(l.done)
|
||||||
<-l.taskLoopDone
|
<-l.taskLoopDone
|
||||||
@@ -104,7 +104,7 @@ func (l *Loop) Done() <-chan struct{} {
|
|||||||
func (l *Loop) Err() error {
|
func (l *Loop) Err() error {
|
||||||
select {
|
select {
|
||||||
case <-l.done:
|
case <-l.done:
|
||||||
return errClosed
|
return ErrClosed
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user