summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-runners/context.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/codeberg.org/gruf/go-runners/context.go')
-rw-r--r--vendor/codeberg.org/gruf/go-runners/context.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/vendor/codeberg.org/gruf/go-runners/context.go b/vendor/codeberg.org/gruf/go-runners/context.go
index 6a0c509cb..9cb6aa5f7 100644
--- a/vendor/codeberg.org/gruf/go-runners/context.go
+++ b/vendor/codeberg.org/gruf/go-runners/context.go
@@ -12,6 +12,11 @@ var closedctx = func() context.Context {
return ctx
}()
+// Closed returns an always closed context.
+func Closed() context.Context {
+ return closedctx
+}
+
// ContextWithCancel returns a new context.Context impl with cancel.
func ContextWithCancel() (context.Context, context.CancelFunc) {
ctx := make(cancelctx)
@@ -41,3 +46,18 @@ func (ctx cancelctx) Err() error {
func (cancelctx) Value(key interface{}) interface{} {
return nil
}
+
+func (ctx cancelctx) String() string {
+ var state string
+ select {
+ case <-ctx:
+ state = "closed"
+ default:
+ state = "open"
+ }
+ return "cancelctx{state:" + state + "}"
+}
+
+func (ctx cancelctx) GoString() string {
+ return "runners." + ctx.String()
+}