Files

25 lines
529 B
Go
Raw Permalink Normal View History

2023-04-18 13:42:05 +02:00
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
2023-02-09 20:41:45 +01:00
// Package atomic contains custom atomic types
package atomic
import "sync/atomic"
2025-01-17 08:21:15 -06:00
// Error is an atomic error.
2023-02-09 20:41:45 +01:00
type Error struct {
v atomic.Value
}
2025-01-17 08:21:15 -06:00
// Store updates the value of the atomic variable.
2023-02-09 20:41:45 +01:00
func (a *Error) Store(err error) {
a.v.Store(struct{ error }{err})
}
2025-01-17 08:21:15 -06:00
// Load retrieves the current value of the atomic variable.
2023-02-09 20:41:45 +01:00
func (a *Error) Load() error {
err, _ := a.v.Load().(struct{ error })
2025-01-17 08:21:15 -06:00
2023-02-09 20:41:45 +01:00
return err.error
}