We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f1f76a3 commit 3e303bcCopy full SHA for 3e303bc
cmdutil/server.go
@@ -58,14 +58,17 @@ func (sf ServerFuncs) Stop(err error) {
58
59
// NewContextServer that when Run(), calls the given function with a context
60
// that is canceled when Stop() is called.
61
-func NewContextServer(fn func(context.Context) error) Server {
+func NewContextServer(fn func(context.Context) error, stopFunc ...func(error)) Server {
62
ctx, cancel := context.WithCancel(context.Background())
63
64
return &ServerFuncs{
65
RunFunc: func() error {
66
return fn(ctx)
67
},
68
- StopFunc: func(error) {
+ StopFunc: func(err error) {
69
+ for _, stop := range stopFunc {
70
+ stop(err)
71
+ }
72
cancel()
73
74
}
0 commit comments