Load cache asynchronously
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package utils
|
||||
|
||||
import "sync/atomic"
|
||||
|
||||
type AtomicBool struct{ flag int32 }
|
||||
|
||||
func (b *AtomicBool) Get() bool {
|
||||
return atomic.LoadInt32(&(b.flag)) != 0
|
||||
}
|
||||
|
||||
func (b *AtomicBool) Set(value bool) {
|
||||
var i int32 = 0
|
||||
if value {
|
||||
i = 1
|
||||
}
|
||||
atomic.StoreInt32(&(b.flag), i)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package utils_test
|
||||
|
||||
import (
|
||||
"github.com/deluan/navidrome/utils"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("AtomicBool", func() {
|
||||
var b utils.AtomicBool
|
||||
|
||||
BeforeEach(func() {
|
||||
b = utils.AtomicBool{}
|
||||
})
|
||||
|
||||
It("initializes with value = false", func() {
|
||||
Expect(b.Get()).To(BeFalse())
|
||||
})
|
||||
|
||||
It("sets value", func() {
|
||||
b.Set(true)
|
||||
Expect(b.Get()).To(BeTrue())
|
||||
|
||||
b.Set(false)
|
||||
Expect(b.Get()).To(BeFalse())
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user