Refactored agents calling into its own struct
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package utils
|
||||
|
||||
import "context"
|
||||
|
||||
func IsCtxDone(ctx context.Context) bool {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -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())
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user