@@ -27,11 +27,19 @@ var (
27
27
28
28
// App specifies functions to control passed HTTP servers.
29
29
type App struct {
30
- // PreServeFn is a common hook notifies client that all servers is
30
+ // PreServeFn is a common hook notifies client that all servers are
31
31
// about to start serving.
32
32
PreServeFn func (inherited bool ) error
33
+
34
+ // CompleteShutdownFn is a parent's hook, a part of shutdown process
35
+ // that allows client to do extra work after all http servers will
36
+ // be shutdown. All dependent resources can be closed here.
37
+ //
38
+ // For stateful services: and before child will start serving.
39
+ CompleteShutdownFn func ()
40
+
33
41
// PreParentExitFn is a child's hook that allows client to do
34
- // something on a child's side before the parent will exit.
42
+ // extra work on a child's side before the parent will exit.
35
43
//
36
44
// Useful e.g. for updating pid in a pid file while acting
37
45
// as a systemd's service.
@@ -47,6 +55,7 @@ type App struct {
47
55
func NewApp (servers ... * http.Server ) * App {
48
56
a := & App {
49
57
PreServeFn : func (inherited bool ) error { return nil },
58
+ CompleteShutdownFn : func () {},
50
59
PreParentExitFn : func () {},
51
60
servers : servers ,
52
61
waitChildTimeout : time .Second * 60 ,
@@ -110,6 +119,7 @@ func (a *App) Shutdown() {
110
119
}
111
120
112
121
wg .Wait ()
122
+ a .CompleteShutdownFn ()
113
123
}
114
124
115
125
// ListenAndServe creates listeners for the given servers or reuses
0 commit comments