:bulb: Atomic Boolean library for cleaner Go code, optimized for performance yet simple to use.
Atomic Boolean package for Go, optimized for performance yet simple to use.
Designed for cleaner code.
import "github.com/tevino/abool"cond := abool.New() // default to false
cond.Set() // Sets to true cond.IsSet() // Returns true cond.UnSet() // Sets to false cond.IsNotSet() // Returns true cond.SetTo(any) // Sets to whatever you want cond.SetToIf(new, old) // Sets to
new
only if the Boolean matches theold
, returns whether succeeded cond.Toggle() // Inverts the boolean then returns the value before inverting// embedding type Foo struct { cond *abool.AtomicBool // always use pointer to avoid copy }
goos: linux goarch: amd64Read
BenchmarkMutexRead-4 86662128 14.2 ns/op BenchmarkAtomicValueRead-4 1000000000 0.755 ns/op BenchmarkAtomicBoolRead-4 1000000000 0.720 ns/op #
Special thanks to contributors
Togglemethod