summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-runners/context.go
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2023-02-06 08:08:22 +0000
committerLibravatar GitHub <noreply@github.com>2023-02-06 08:08:22 +0000
commit0a9874329d64984cb6dd0fb13b501e266f613745 (patch)
treed98177145867f65fbe8d59b8e9a7898d3b0dd1f4 /vendor/codeberg.org/gruf/go-runners/context.go
parent[chore]: Bump github.com/yuin/goldmark from 1.5.3 to 1.5.4 (#1427) (diff)
downloadgotosocial-0a9874329d64984cb6dd0fb13b501e266f613745.tar.xz
[chore]: Bump codeberg.org/gruf/go-runners from 1.4.0 to 1.5.1 (#1428)
Bumps codeberg.org/gruf/go-runners from 1.4.0 to 1.5.1. --- updated-dependencies: - dependency-name: codeberg.org/gruf/go-runners dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/codeberg.org/gruf/go-runners/context.go')
-rw-r--r--vendor/codeberg.org/gruf/go-runners/context.go31
1 files changed, 16 insertions, 15 deletions
diff --git a/vendor/codeberg.org/gruf/go-runners/context.go b/vendor/codeberg.org/gruf/go-runners/context.go
index 9cb6aa5f7..12f7f1a10 100644
--- a/vendor/codeberg.org/gruf/go-runners/context.go
+++ b/vendor/codeberg.org/gruf/go-runners/context.go
@@ -7,9 +7,9 @@ import (
// closedctx is an always closed context.
var closedctx = func() context.Context {
- ctx := make(cancelctx)
+ ctx := make(chan struct{})
close(ctx)
- return ctx
+ return CancelCtx(ctx)
}()
// Closed returns an always closed context.
@@ -17,24 +17,25 @@ func Closed() context.Context {
return closedctx
}
-// ContextWithCancel returns a new context.Context impl with cancel.
-func ContextWithCancel() (context.Context, context.CancelFunc) {
- ctx := make(cancelctx)
- return ctx, func() { close(ctx) }
+// CtxWithCancel returns a new context.Context impl with cancel.
+func CtxWithCancel() (context.Context, context.CancelFunc) {
+ ctx := make(chan struct{})
+ cncl := func() { close(ctx) }
+ return CancelCtx(ctx), cncl
}
-// cancelctx is the simplest possible cancellable context.
-type cancelctx (chan struct{})
+// CancelCtx is the simplest possible cancellable context.
+type CancelCtx (<-chan struct{})
-func (cancelctx) Deadline() (time.Time, bool) {
+func (CancelCtx) Deadline() (time.Time, bool) {
return time.Time{}, false
}
-func (ctx cancelctx) Done() <-chan struct{} {
+func (ctx CancelCtx) Done() <-chan struct{} {
return ctx
}
-func (ctx cancelctx) Err() error {
+func (ctx CancelCtx) Err() error {
select {
case <-ctx:
return context.Canceled
@@ -43,11 +44,11 @@ func (ctx cancelctx) Err() error {
}
}
-func (cancelctx) Value(key interface{}) interface{} {
+func (CancelCtx) Value(key interface{}) interface{} {
return nil
}
-func (ctx cancelctx) String() string {
+func (ctx CancelCtx) String() string {
var state string
select {
case <-ctx:
@@ -55,9 +56,9 @@ func (ctx cancelctx) String() string {
default:
state = "open"
}
- return "cancelctx{state:" + state + "}"
+ return "CancelCtx{state:" + state + "}"
}
-func (ctx cancelctx) GoString() string {
+func (ctx CancelCtx) GoString() string {
return "runners." + ctx.String()
}