summaryrefslogtreecommitdiff
path: root/vendor/go.uber.org/atomic/error.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/go.uber.org/atomic/error.go')
-rw-r--r--vendor/go.uber.org/atomic/error.go48
1 files changed, 22 insertions, 26 deletions
diff --git a/vendor/go.uber.org/atomic/error.go b/vendor/go.uber.org/atomic/error.go
index 0489d19ba..a6166fbea 100644
--- a/vendor/go.uber.org/atomic/error.go
+++ b/vendor/go.uber.org/atomic/error.go
@@ -1,4 +1,6 @@
-// Copyright (c) 2016 Uber Technologies, Inc.
+// @generated Code generated by gen-atomicwrapper.
+
+// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -20,36 +22,30 @@
package atomic
-// Error is an atomic type-safe wrapper around Value for errors
-type Error struct{ v Value }
-
-// errorHolder is non-nil holder for error object.
-// atomic.Value panics on saving nil object, so err object needs to be
-// wrapped with valid object first.
-type errorHolder struct{ err error }
+// Error is an atomic type-safe wrapper for error values.
+type Error struct {
+ _ nocmp // disallow non-atomic comparison
-// NewError creates new atomic error object
-func NewError(err error) *Error {
- e := &Error{}
- if err != nil {
- e.Store(err)
- }
- return e
+ v Value
}
-// Load atomically loads the wrapped error
-func (e *Error) Load() error {
- v := e.v.Load()
- if v == nil {
- return nil
+var _zeroError error
+
+// NewError creates a new Error.
+func NewError(v error) *Error {
+ x := &Error{}
+ if v != _zeroError {
+ x.Store(v)
}
+ return x
+}
- eh := v.(errorHolder)
- return eh.err
+// Load atomically loads the wrapped error.
+func (x *Error) Load() error {
+ return unpackError(x.v.Load())
}
-// Store atomically stores error.
-// NOTE: a holder object is allocated on each Store call.
-func (e *Error) Store(err error) {
- e.v.Store(errorHolder{err: err})
+// Store atomically stores the passed error.
+func (x *Error) Store(v error) {
+ x.v.Store(packError(v))
}