diff options
author | 2023-01-06 10:16:09 +0000 | |
---|---|---|
committer | 2023-01-06 11:16:09 +0100 | |
commit | adbc87700a5bc7a95883ba5b9688d8b946a8db48 (patch) | |
tree | 6030ff70d3eb0b9a0b8fc7d5fca378a77033d546 /vendor/codeberg.org/gruf/go-runners/context.go | |
parent | [chore] Update/add license headers for 2023 (#1304) (diff) | |
download | gotosocial-adbc87700a5bc7a95883ba5b9688d8b946a8db48.tar.xz |
[chore] pull in latest go-cache, go-runners versions (#1306)
Signed-off-by: kim <grufwub@gmail.com>
Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/codeberg.org/gruf/go-runners/context.go')
-rw-r--r-- | vendor/codeberg.org/gruf/go-runners/context.go | 20 |
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() +} |