mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
Removed unused diodes
package
This commit is contained in:
parent
6d924ad742
commit
ac3668a33e
4 changed files with 0 additions and 103 deletions
1
go.mod
1
go.mod
|
@ -3,7 +3,6 @@ module github.com/navidrome/navidrome
|
|||
go 1.21
|
||||
|
||||
require (
|
||||
code.cloudfoundry.org/go-diodes v0.0.0-20231113191959-85adc333ee36
|
||||
github.com/DexterLB/mpvipc v0.0.0-20230829142118-145d6eabdc37
|
||||
github.com/Masterminds/squirrel v1.5.4
|
||||
github.com/ReneKroon/ttlcache/v2 v2.11.0
|
||||
|
|
2
go.sum
2
go.sum
|
@ -35,8 +35,6 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
|
|||
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
|
||||
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
|
||||
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
|
||||
code.cloudfoundry.org/go-diodes v0.0.0-20231113191959-85adc333ee36 h1:rvJrEWqzJVIgzhVGzm3zRFWN46W+Rk6QkmfATsvv7MA=
|
||||
code.cloudfoundry.org/go-diodes v0.0.0-20231113191959-85adc333ee36/go.mod h1:+ARlrrIHjT9DE+ge1VugVtIs/DAOW8Cim8dKtspdkbc=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
package diodes
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.cloudfoundry.org/go-diodes"
|
||||
)
|
||||
|
||||
type Diode[T any] struct {
|
||||
d *diodes.Waiter
|
||||
}
|
||||
|
||||
type Alerter = diodes.Alerter
|
||||
|
||||
type AlertFunc = diodes.AlertFunc
|
||||
|
||||
func New[T any](ctx context.Context, size int, alerter Alerter) *Diode[T] {
|
||||
return &Diode[T]{
|
||||
d: diodes.NewWaiter(diodes.NewOneToOne(size, alerter), diodes.WithWaiterContext(ctx)),
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Diode[T]) Put(data T) {
|
||||
d.d.Set(diodes.GenericDataType(&data))
|
||||
}
|
||||
|
||||
func (d *Diode[T]) TryNext() (*T, bool) {
|
||||
data, ok := d.d.TryNext()
|
||||
if !ok {
|
||||
return nil, ok
|
||||
}
|
||||
return (*T)(data), true
|
||||
}
|
||||
|
||||
func (d *Diode[T]) Next() *T {
|
||||
data := d.d.Next()
|
||||
return (*T)(data)
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
package diodes_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/navidrome/navidrome/tests"
|
||||
. "github.com/navidrome/navidrome/utils/diodes"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestDiodes(t *testing.T) {
|
||||
tests.Init(t, false)
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Diodes Suite")
|
||||
}
|
||||
|
||||
var _ = Describe("Diode", func() {
|
||||
type message struct {
|
||||
data string
|
||||
}
|
||||
var diode *Diode[message]
|
||||
var ctx context.Context
|
||||
var ctxCancel context.CancelFunc
|
||||
var missed int
|
||||
|
||||
BeforeEach(func() {
|
||||
missed = 0
|
||||
ctx, ctxCancel = context.WithCancel(context.Background())
|
||||
diode = New[message](ctx, 2, AlertFunc(func(m int) { missed = m }))
|
||||
})
|
||||
|
||||
It("enqueues the data correctly", func() {
|
||||
diode.Put(message{data: "1"})
|
||||
diode.Put(message{data: "2"})
|
||||
Expect(diode.Next()).To(Equal(&message{data: "1"}))
|
||||
Expect(diode.Next()).To(Equal(&message{data: "2"}))
|
||||
Expect(missed).To(BeZero())
|
||||
})
|
||||
|
||||
It("drops messages when Diode is full", func() {
|
||||
diode.Put(message{data: "1"})
|
||||
diode.Put(message{data: "2"})
|
||||
diode.Put(message{data: "3"})
|
||||
next, ok := diode.TryNext()
|
||||
Expect(ok).To(BeTrue())
|
||||
Expect(next).To(Equal(&message{data: "3"}))
|
||||
|
||||
_, ok = diode.TryNext()
|
||||
Expect(ok).To(BeFalse())
|
||||
|
||||
Expect(missed).To(Equal(2))
|
||||
})
|
||||
|
||||
It("returns nil when Diode is empty and the context is canceled", func() {
|
||||
diode.Put(message{data: "1"})
|
||||
ctxCancel()
|
||||
Expect(diode.Next()).To(Equal(&message{data: "1"}))
|
||||
Expect(diode.Next()).To(BeNil())
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue