You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/core/errorx/atomicerror.go

22 lines
355 B
Go

4 years ago
package errorx
import "sync/atomic"
4 years ago
// AtomicError defines an atomic error.
4 years ago
type AtomicError struct {
err atomic.Value // error
4 years ago
}
// Set sets the error.
4 years ago
func (ae *AtomicError) Set(err error) {
ae.err.Store(err)
4 years ago
}
// Load returns the error.
4 years ago
func (ae *AtomicError) Load() error {
if v := ae.err.Load(); v != nil {
return v.(error)
}
return nil
4 years ago
}