Files
go-zero/core/errorx/atomicerror.go

22 lines
355 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package errorx
import "sync/atomic"
2020-07-26 17:09:05 +08:00
2021-02-08 21:31:56 +08:00
// AtomicError defines an atomic error.
2020-07-26 17:09:05 +08:00
type AtomicError struct {
err atomic.Value // error
2020-07-26 17:09:05 +08:00
}
2021-02-08 21:31:56 +08:00
// Set sets the error.
2020-07-26 17:09:05 +08:00
func (ae *AtomicError) Set(err error) {
ae.err.Store(err)
2020-07-26 17:09:05 +08:00
}
2021-02-08 21:31:56 +08:00
// Load returns the error.
2020-07-26 17:09:05 +08:00
func (ae *AtomicError) Load() error {
if v := ae.err.Load(); v != nil {
return v.(error)
}
return nil
2020-07-26 17:09:05 +08:00
}