Refactored agents calling into its own struct

This commit is contained in:
Deluan 2021-06-08 16:57:19 -04:00
commit f9eec5e4dc
5 changed files with 511 additions and 185 deletions

12
utils/context.go Normal file
View file

@ -0,0 +1,12 @@
package utils
import "context"
func IsCtxDone(ctx context.Context) bool {
select {
case <-ctx.Done():
return true
default:
return false
}
}

23
utils/context_test.go Normal file
View file

@ -0,0 +1,23 @@
package utils_test
import (
"context"
"github.com/navidrome/navidrome/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("IsCtxDone", func() {
It("returns false if the context is not done", func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expect(utils.IsCtxDone(ctx)).To(BeFalse())
})
It("returns true if the context is done", func() {
ctx, cancel := context.WithCancel(context.Background())
cancel()
Expect(utils.IsCtxDone(ctx)).To(BeTrue())
})
})