From ac3668a33e44ea5c1f7433551fc75d048131d6bc Mon Sep 17 00:00:00 2001 From: Deluan Date: Mon, 11 Dec 2023 17:22:10 -0500 Subject: [PATCH] Removed unused `diodes` package --- go.mod | 1 - go.sum | 2 -- utils/diodes/diodes.go | 38 ----------------------- utils/diodes/diodes_test.go | 62 ------------------------------------- 4 files changed, 103 deletions(-) delete mode 100644 utils/diodes/diodes.go delete mode 100644 utils/diodes/diodes_test.go diff --git a/go.mod b/go.mod index 6d460f01d..4b8bc703a 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index a5a4008dc..dbb28ad38 100644 --- a/go.sum +++ b/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= diff --git a/utils/diodes/diodes.go b/utils/diodes/diodes.go deleted file mode 100644 index 64e2e436f..000000000 --- a/utils/diodes/diodes.go +++ /dev/null @@ -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) -} diff --git a/utils/diodes/diodes_test.go b/utils/diodes/diodes_test.go deleted file mode 100644 index fda9746e2..000000000 --- a/utils/diodes/diodes_test.go +++ /dev/null @@ -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()) - }) -})