build(deps): bump github.com/oklog/run from 1.1.0 to 1.2.0

Bumps [github.com/oklog/run](https://github.com/oklog/run) from 1.1.0 to 1.2.0.
- [Release notes](https://github.com/oklog/run/releases)
- [Commits](https://github.com/oklog/run/compare/v1.1.0...v1.2.0)

---
updated-dependencies:
- dependency-name: github.com/oklog/run
  dependency-version: 1.2.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot]
2025-06-30 17:46:21 +00:00
committed by GitHub
parent 7d6bc2a485
commit ab321b744c
6 changed files with 96 additions and 22 deletions

2
go.mod
View File

@@ -57,7 +57,7 @@ require (
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/nats-io/nats-server/v2 v2.11.5
github.com/nats-io/nats.go v1.43.0
github.com/oklog/run v1.1.0
github.com/oklog/run v1.2.0
github.com/olekukonko/tablewriter v1.0.7
github.com/onsi/ginkgo v1.16.5
github.com/onsi/ginkgo/v2 v2.23.4

4
go.sum
View File

@@ -842,8 +842,8 @@ github.com/nrdcg/porkbun v0.1.1/go.mod h1:JWl/WKnguWos4mjfp4YizvvToigk9qpQwrodOk
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
github.com/oklog/run v1.2.0 h1:O8x3yXwah4A73hJdlrwo/2X6J62gE5qTMusH0dvz60E=
github.com/oklog/run v1.2.0/go.mod h1:mgDbKRSwPhJfesJ4PntqFUbKQRZ50NgmZTSPlFA0YFk=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/olekukonko/errors v0.0.0-20250405072817-4e6d85265da6 h1:r3FaAI0NZK3hSmtTDrBVREhKULp8oUeqLT5Eyl2mSPo=
github.com/olekukonko/errors v0.0.0-20250405072817-4e6d85265da6/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y=

View File

@@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Copyright 2017 Peter Bourgon
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View File

@@ -1,7 +1,7 @@
# run
[![GoDoc](https://godoc.org/github.com/oklog/run?status.svg)](https://godoc.org/github.com/oklog/run)
[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Foklog%2Frun%2Fbadge&style=flat-square&label=build)](https://github.com/oklog/run/actions?query=workflow%3ATest)
[![GoDoc](https://godoc.org/github.com/oklog/run?status.svg)](https://godoc.org/github.com/oklog/run)
[![test](https://github.com/oklog/run/actions/workflows/test.yaml/badge.svg?branch=main&event=push)](https://github.com/oklog/run/actions/workflows/test.yaml)
[![Go Report Card](https://goreportcard.com/badge/github.com/oklog/run)](https://goreportcard.com/report/github.com/oklog/run)
[![Apache 2 licensed](https://img.shields.io/badge/license-Apache2-blue.svg)](https://raw.githubusercontent.com/oklog/run/master/LICENSE)
@@ -16,8 +16,8 @@ finally returns control to the caller only once all actors have returned. This
general-purpose API allows callers to model pretty much any runnable task, and
achieve well-defined lifecycle semantics for the group.
run.Group was written to manage component lifecycles in func main for
[OK Log](https://github.com/oklog/oklog).
run.Group was written to manage component lifecycles in func main for
[OK Log](https://github.com/oklog/oklog).
But it's useful in any circumstance where you need to orchestrate multiple
goroutines as a unit whole.
[Click here](https://www.youtube.com/watch?v=LHe1Cb_Ud_M&t=15m45s) to see a
@@ -62,14 +62,30 @@ g.Add(func() error {
})
```
### http.Server graceful Shutdown
```go
httpServer := &http.Server{
Addr: "localhost:8080",
Handler: ...,
}
g.Add(func() error {
return httpServer.ListenAndServe()
}, func(error) {
ctx, cancel := context.WithTimeout(context.TODO(), 3*time.Second)
defer cancel()
httpServer.Shutdown(ctx)
})
```
## Comparisons
Package run is somewhat similar to package
[errgroup](https://godoc.org/golang.org/x/sync/errgroup),
Package run is somewhat similar to package
[errgroup](https://godoc.org/golang.org/x/sync/errgroup),
except it doesn't require actor goroutines to understand context semantics.
It's somewhat similar to package
[tomb.v1](https://godoc.org/gopkg.in/tomb.v1) or
[tomb.v1](https://godoc.org/gopkg.in/tomb.v1) or
[tomb.v2](https://godoc.org/gopkg.in/tomb.v2),
except it has a much smaller API surface, delegating e.g. staged shutdown of
except it has a much smaller API surface, delegating e.g. staged shutdown of
goroutines to the caller.

View File

@@ -2,22 +2,41 @@ package run
import (
"context"
"errors"
"fmt"
"os"
"os/signal"
)
// ContextHandler returns an actor, i.e. an execute and interrupt func, that
// terminates when the provided context is canceled.
func ContextHandler(ctx context.Context) (execute func() error, interrupt func(error)) {
ctx, cancel := context.WithCancel(ctx)
return func() error {
<-ctx.Done()
return ctx.Err()
}, func(error) {
cancel()
}
}
// SignalHandler returns an actor, i.e. an execute and interrupt func, that
// terminates with SignalError when the process receives one of the provided
// signals, or the parent context is canceled.
// terminates with ErrSignal when the process receives one of the provided
// signals, or with ctx.Error() when the parent context is canceled. If no
// signals are provided, the actor will terminate on any signal, per
// [signal.Notify].
func SignalHandler(ctx context.Context, signals ...os.Signal) (execute func() error, interrupt func(error)) {
ctx, cancel := context.WithCancel(ctx)
return func() error {
c := make(chan os.Signal, 1)
signal.Notify(c, signals...)
testc := getTestSigChan(ctx)
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, signals...)
defer signal.Stop(sigc)
select {
case sig := <-c:
return SignalError{Signal: sig}
case sig := <-testc:
return &SignalError{Signal: sig}
case sig := <-sigc:
return &SignalError{Signal: sig}
case <-ctx.Done():
return ctx.Err()
}
@@ -26,13 +45,52 @@ func SignalHandler(ctx context.Context, signals ...os.Signal) (execute func() er
}
}
// SignalError is returned by the signal handler's execute function
// when it terminates due to a received signal.
type testSigChanKey struct{}
func getTestSigChan(ctx context.Context) <-chan os.Signal {
c, _ := ctx.Value(testSigChanKey{}).(<-chan os.Signal) // can be nil
return c
}
func putTestSigChan(ctx context.Context, c <-chan os.Signal) context.Context {
return context.WithValue(ctx, testSigChanKey{}, c)
}
// SignalError is returned by the signal handler's execute function when it
// terminates due to a received signal.
//
// SignalError has a design error that impacts comparison with errors.As.
// Callers should prefer using errors.Is(err, ErrSignal) to check for signal
// errors, and should only use errors.As in the rare case that they need to
// program against the specific os.Signal value.
type SignalError struct {
Signal os.Signal
}
// Error implements the error interface.
//
// It was a design error to define this method on a value receiver rather than a
// pointer receiver. For compatibility reasons it won't be changed.
func (e SignalError) Error() string {
return fmt.Sprintf("received signal %s", e.Signal)
}
// Is addresses a design error in the SignalError type, so that errors.Is with
// ErrSignal will return true.
func (e SignalError) Is(err error) bool {
return errors.Is(err, ErrSignal)
}
// As fixes a design error in the SignalError type, so that errors.As with the
// literal `&SignalError{}` will return true.
func (e SignalError) As(target interface{}) bool {
switch target.(type) {
case *SignalError, SignalError:
return true
default:
return false
}
}
// ErrSignal is returned by SignalHandler when a signal triggers termination.
var ErrSignal = errors.New("signal error")

4
vendor/modules.txt vendored
View File

@@ -1032,8 +1032,8 @@ github.com/nxadm/tail/ratelimiter
github.com/nxadm/tail/util
github.com/nxadm/tail/watch
github.com/nxadm/tail/winfile
# github.com/oklog/run v1.1.0
## explicit; go 1.13
# github.com/oklog/run v1.2.0
## explicit; go 1.20
github.com/oklog/run
# github.com/olekukonko/errors v0.0.0-20250405072817-4e6d85265da6
## explicit; go 1.21