atomic.go 525 B

1234567891011121314151617181920212223
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. // Package atomic contains custom atomic types
  4. package atomic
  5. import "sync/atomic"
  6. // Error is an atomic error
  7. type Error struct {
  8. v atomic.Value
  9. }
  10. // Store updates the value of the atomic variable
  11. func (a *Error) Store(err error) {
  12. a.v.Store(struct{ error }{err})
  13. }
  14. // Load retrieves the current value of the atomic variable
  15. func (a *Error) Load() error {
  16. err, _ := a.v.Load().(struct{ error })
  17. return err.error
  18. }