[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
commit 0a9874329d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 40 deletions

View file

@ -8,10 +8,10 @@ import (
// Service provides a means of tracking a single long-running service, provided protected state
// changes and preventing multiple instances running. Also providing service state information.
type Service struct {
state uint32 // 0=stopped, 1=running, 2=stopping
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'
ctx cancelctx // ctx is the current context for running function (or nil if not running)
state uint32 // 0=stopped, 1=running, 2=stopping
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'
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.
@ -31,8 +31,8 @@ func (svc *Service) Run(fn func(context.Context)) bool {
_ = svc.Stop()
}()
// Run
fn(ctx)
// Run with context.
fn(CancelCtx(ctx))
return true
}
@ -55,8 +55,8 @@ func (svc *Service) GoRun(fn func(context.Context)) bool {
_ = svc.Stop()
}()
// Run
fn(ctx)
// Run with context.
fn(CancelCtx(ctx))
}()
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.
func (svc *Service) doStart() (cancelctx, bool) {
func (svc *Service) doStart() (chan struct{}, bool) {
// Protect startup
svc.mutex.Lock()
@ -119,7 +119,7 @@ func (svc *Service) doStart() (cancelctx, bool) {
if svc.ctx == nil {
// this will only have been allocated
// if svc.Done() was already called.
svc.ctx = make(cancelctx)
svc.ctx = make(chan struct{})
}
// 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.
func (svc *Service) doStop() (cancelctx, bool) {
func (svc *Service) doStop() (chan struct{}, bool) {
// Protect stop
svc.mutex.Lock()
@ -175,7 +175,7 @@ func (svc *Service) Done() <-chan struct{} {
// here we create a new context so that the
// returned 'done' channel here will still
// be valid for when Service is next started.
svc.ctx = make(cancelctx)
svc.ctx = make(chan struct{})
}
done = svc.ctx