Skip to content

Commit 3e303bc

Browse files
committed
add stop function to ContextWServer
1 parent f1f76a3 commit 3e303bc

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

cmdutil/server.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,17 @@ func (sf ServerFuncs) Stop(err error) {
5858

5959
// NewContextServer that when Run(), calls the given function with a context
6060
// that is canceled when Stop() is called.
61-
func NewContextServer(fn func(context.Context) error) Server {
61+
func NewContextServer(fn func(context.Context) error, stopFunc ...func(error)) Server {
6262
ctx, cancel := context.WithCancel(context.Background())
6363

6464
return &ServerFuncs{
6565
RunFunc: func() error {
6666
return fn(ctx)
6767
},
68-
StopFunc: func(error) {
68+
StopFunc: func(err error) {
69+
for _, stop := range stopFunc {
70+
stop(err)
71+
}
6972
cancel()
7073
},
7174
}

0 commit comments

Comments
 (0)