[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>
This commit is contained in:
dependabot[bot] 2023-02-06 08:08:22 +00:00 committed by GitHub
parent 1df25a3592
commit 0a9874329d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 40 deletions

2
go.mod
View file

@ -11,7 +11,7 @@ require (
codeberg.org/gruf/go-kv v1.5.2 codeberg.org/gruf/go-kv v1.5.2
codeberg.org/gruf/go-logger/v2 v2.2.1 codeberg.org/gruf/go-logger/v2 v2.2.1
codeberg.org/gruf/go-mutexes v1.1.5 codeberg.org/gruf/go-mutexes v1.1.5
codeberg.org/gruf/go-runners v1.4.0 codeberg.org/gruf/go-runners v1.5.1
codeberg.org/gruf/go-store/v2 v2.2.1 codeberg.org/gruf/go-store/v2 v2.2.1
github.com/KimMachineGun/automemlimit v0.2.4 github.com/KimMachineGun/automemlimit v0.2.4
github.com/abema/go-mp4 v0.10.0 github.com/abema/go-mp4 v0.10.0

4
go.sum
View file

@ -79,8 +79,8 @@ codeberg.org/gruf/go-mutexes v1.1.5 h1:8Y8DwCGf24MyzOSaPvLrtk/B4ecVx4z+fppL6dY+P
codeberg.org/gruf/go-mutexes v1.1.5/go.mod h1:1j/6/MBeBQUedAtAtysLLnBKogfOZAxdym0E3wlaBD8= codeberg.org/gruf/go-mutexes v1.1.5/go.mod h1:1j/6/MBeBQUedAtAtysLLnBKogfOZAxdym0E3wlaBD8=
codeberg.org/gruf/go-pools v1.1.0 h1:LbYP24eQLl/YI1fSU2pafiwhGol1Z1zPjRrMsXpF88s= codeberg.org/gruf/go-pools v1.1.0 h1:LbYP24eQLl/YI1fSU2pafiwhGol1Z1zPjRrMsXpF88s=
codeberg.org/gruf/go-pools v1.1.0/go.mod h1:ZMYpt/DjQWYC3zFD3T97QWSFKs62zAUGJ/tzvgB9D68= codeberg.org/gruf/go-pools v1.1.0/go.mod h1:ZMYpt/DjQWYC3zFD3T97QWSFKs62zAUGJ/tzvgB9D68=
codeberg.org/gruf/go-runners v1.4.0 h1:977nVjigAdH95+VAB/a6tyBJOKk99e60h+mfHzBs/n8= codeberg.org/gruf/go-runners v1.5.1 h1:ekhhxKvO6D/VC7nS/xpv71/iRX01JSqcBEbahqPUghg=
codeberg.org/gruf/go-runners v1.4.0/go.mod h1:kUM6GYL7dC+f9Sc/XuwdvB/mB4FuI4fJFb150ADMsmw= codeberg.org/gruf/go-runners v1.5.1/go.mod h1:kUM6GYL7dC+f9Sc/XuwdvB/mB4FuI4fJFb150ADMsmw=
codeberg.org/gruf/go-sched v1.2.0 h1:utZl/7srVcbh30rFw42LC2/cMtak4UZRxtIOt/5riNA= codeberg.org/gruf/go-sched v1.2.0 h1:utZl/7srVcbh30rFw42LC2/cMtak4UZRxtIOt/5riNA=
codeberg.org/gruf/go-sched v1.2.0/go.mod h1:v4ueWq+fAtAw9JYt4aFXvadI1YoOqofgHQgszRYuslA= codeberg.org/gruf/go-sched v1.2.0/go.mod h1:v4ueWq+fAtAw9JYt4aFXvadI1YoOqofgHQgszRYuslA=
codeberg.org/gruf/go-store/v2 v2.2.1 h1:lbvMjhMLebefiaPNLtWvPySKSYM5xN1aztSxxz+vCzU= codeberg.org/gruf/go-store/v2 v2.2.1 h1:lbvMjhMLebefiaPNLtWvPySKSYM5xN1aztSxxz+vCzU=

View file

@ -7,9 +7,9 @@
// closedctx is an always closed context. // closedctx is an always closed context.
var closedctx = func() context.Context { var closedctx = func() context.Context {
ctx := make(cancelctx) ctx := make(chan struct{})
close(ctx) close(ctx)
return ctx return CancelCtx(ctx)
}() }()
// Closed returns an always closed context. // Closed returns an always closed context.
@ -17,24 +17,25 @@ func Closed() context.Context {
return closedctx return closedctx
} }
// ContextWithCancel returns a new context.Context impl with cancel. // CtxWithCancel returns a new context.Context impl with cancel.
func ContextWithCancel() (context.Context, context.CancelFunc) { func CtxWithCancel() (context.Context, context.CancelFunc) {
ctx := make(cancelctx) ctx := make(chan struct{})
return ctx, func() { close(ctx) } cncl := func() { close(ctx) }
return CancelCtx(ctx), cncl
} }
// cancelctx is the simplest possible cancellable context. // CancelCtx is the simplest possible cancellable context.
type cancelctx (chan struct{}) type CancelCtx (<-chan struct{})
func (cancelctx) Deadline() (time.Time, bool) { func (CancelCtx) Deadline() (time.Time, bool) {
return time.Time{}, false return time.Time{}, false
} }
func (ctx cancelctx) Done() <-chan struct{} { func (ctx CancelCtx) Done() <-chan struct{} {
return ctx return ctx
} }
func (ctx cancelctx) Err() error { func (ctx CancelCtx) Err() error {
select { select {
case <-ctx: case <-ctx:
return context.Canceled 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 return nil
} }
func (ctx cancelctx) String() string { func (ctx CancelCtx) String() string {
var state string var state string
select { select {
case <-ctx: case <-ctx:
@ -55,9 +56,9 @@ func (ctx cancelctx) String() string {
default: default:
state = "open" state = "open"
} }
return "cancelctx{state:" + state + "}" return "CancelCtx{state:" + state + "}"
} }
func (ctx cancelctx) GoString() string { func (ctx CancelCtx) GoString() string {
return "runners." + ctx.String() return "runners." + ctx.String()
} }

View file

@ -67,20 +67,14 @@ func (pool *WorkerPool) Start(workers int, queue int) bool {
go func() { go func() {
defer wait.Done() defer wait.Done()
// Run worker function. // Run worker function (retry on panic)
for !worker_run(ctx, fns) { for !worker_run(CancelCtx(ctx), fns) {
// retry on panic
} }
}() }()
} }
// Set GC finalizer to stop pool on dealloc.
runtime.SetFinalizer(pool, func(pool *WorkerPool) {
_ = pool.svc.Stop()
})
// Wait on ctx // Wait on ctx
<-ctx.Done() <-ctx
// Drain function queue. // Drain function queue.
// //
@ -110,6 +104,16 @@ func (pool *WorkerPool) Stop() bool {
return pool.svc.Stop() return pool.svc.Stop()
} }
// Running returns if WorkerPool management loop is running (i.e. NOT stopped / stopping).
func (pool *WorkerPool) Running() bool {
return pool.svc.Running()
}
// Done returns a channel that's closed when WorkerPool.Stop() is called. It is the same channel provided to the currently running worker functions.
func (pool *WorkerPool) Done() <-chan struct{} {
return pool.svc.Done()
}
// Enqueue will add provided WorkerFunc to the queue to be performed when there is a free worker. // Enqueue will add provided WorkerFunc to the queue to be performed when there is a free worker.
// This will block until function is queued or pool is stopped. In all cases, the WorkerFunc will be // This will block until function is queued or pool is stopped. In all cases, the WorkerFunc will be
// executed, with the state of the pool being indicated by <-ctx.Done() of the passed ctx. // executed, with the state of the pool being indicated by <-ctx.Done() of the passed ctx.

View file

@ -11,7 +11,7 @@ type Service struct {
state uint32 // 0=stopped, 1=running, 2=stopping state uint32 // 0=stopped, 1=running, 2=stopping
mutex sync.Mutex // mutext protects overall state changes mutex sync.Mutex // mutext protects overall state changes
wait sync.Mutex // wait is used as a single-entity wait-group, only ever locked within 'mutex' wait sync.Mutex // wait is used as a single-entity wait-group, only ever locked within 'mutex'
ctx cancelctx // ctx is the current context for running function (or nil if not running) ctx chan struct{} // ctx is the current context for running function (or nil if not running)
} }
// Run will run the supplied function until completion, using given context to propagate cancel. // Run will run the supplied function until completion, using given context to propagate cancel.
@ -31,8 +31,8 @@ func (svc *Service) Run(fn func(context.Context)) bool {
_ = svc.Stop() _ = svc.Stop()
}() }()
// Run // Run with context.
fn(ctx) fn(CancelCtx(ctx))
return true return true
} }
@ -55,8 +55,8 @@ func (svc *Service) GoRun(fn func(context.Context)) bool {
_ = svc.Stop() _ = svc.Stop()
}() }()
// Run // Run with context.
fn(ctx) fn(CancelCtx(ctx))
}() }()
return true return true
@ -104,7 +104,7 @@ func (svc *Service) While(fn func()) {
} }
// doStart will safely set Service state to started, returning a ptr to this context insance. // doStart will safely set Service state to started, returning a ptr to this context insance.
func (svc *Service) doStart() (cancelctx, bool) { func (svc *Service) doStart() (chan struct{}, bool) {
// Protect startup // Protect startup
svc.mutex.Lock() svc.mutex.Lock()
@ -119,7 +119,7 @@ func (svc *Service) doStart() (cancelctx, bool) {
if svc.ctx == nil { if svc.ctx == nil {
// this will only have been allocated // this will only have been allocated
// if svc.Done() was already called. // if svc.Done() was already called.
svc.ctx = make(cancelctx) svc.ctx = make(chan struct{})
} }
// Start the waiter // Start the waiter
@ -134,7 +134,7 @@ func (svc *Service) doStart() (cancelctx, bool) {
} }
// doStop will safely set Service state to stopping, returning a ptr to this cancelfunc instance. // doStop will safely set Service state to stopping, returning a ptr to this cancelfunc instance.
func (svc *Service) doStop() (cancelctx, bool) { func (svc *Service) doStop() (chan struct{}, bool) {
// Protect stop // Protect stop
svc.mutex.Lock() svc.mutex.Lock()
@ -175,7 +175,7 @@ func (svc *Service) Done() <-chan struct{} {
// here we create a new context so that the // here we create a new context so that the
// returned 'done' channel here will still // returned 'done' channel here will still
// be valid for when Service is next started. // be valid for when Service is next started.
svc.ctx = make(cancelctx) svc.ctx = make(chan struct{})
} }
done = svc.ctx done = svc.ctx

2
vendor/modules.txt vendored
View file

@ -58,7 +58,7 @@ codeberg.org/gruf/go-mutexes
# codeberg.org/gruf/go-pools v1.1.0 # codeberg.org/gruf/go-pools v1.1.0
## explicit; go 1.16 ## explicit; go 1.16
codeberg.org/gruf/go-pools codeberg.org/gruf/go-pools
# codeberg.org/gruf/go-runners v1.4.0 # codeberg.org/gruf/go-runners v1.5.1
## explicit; go 1.14 ## explicit; go 1.14
codeberg.org/gruf/go-runners codeberg.org/gruf/go-runners
# codeberg.org/gruf/go-sched v1.2.0 # codeberg.org/gruf/go-sched v1.2.0