github.com/lingyao2333/mo-zero@v1.4.1/core/errorx/atomicerror.go (about)

     1  package errorx
     2  
     3  import "sync/atomic"
     4  
     5  // AtomicError defines an atomic error.
     6  type AtomicError struct {
     7  	err atomic.Value // error
     8  }
     9  
    10  // Set sets the error.
    11  func (ae *AtomicError) Set(err error) {
    12  	if err != nil {
    13  		ae.err.Store(err)
    14  	}
    15  }
    16  
    17  // Load returns the error.
    18  func (ae *AtomicError) Load() error {
    19  	if v := ae.err.Load(); v != nil {
    20  		return v.(error)
    21  	}
    22  	return nil
    23  }