File tree Expand file tree Collapse file tree 1 file changed +12
-20
lines changed
Expand file tree Collapse file tree 1 file changed +12
-20
lines changed Original file line number Diff line number Diff line change @@ -100,26 +100,18 @@ func main() {
100100 RunTask (ctx)
101101 }(keeper.AllocHoldToken ())
102102
103- go func () {
104- server := &http.Server {
105- Addr: " :8011" ,
106- Handler: http.HandlerFunc (func (w http.ResponseWriter , r *http.Request ) {
107- if r.Method == " POST" && r.URL .Path == " /shutdown" {
108- cancel ()
109- return
110- }
111- // ...
112- }),
113- }
114- go func (token shutdownKeeper.HoldToken ) {
115- defer token.Release ()
116-
117- // ListenShutdown will block until the context is canceled.
118- token.ListenShutdown ()
119- server.Shutdown (context.Background ())
120- }(keeper.AllocHoldToken ())
121- _ = server.ListenAndServe ()
122- }()
103+ server := &http.Server {
104+ Addr: " :8011" ,
105+ Handler: http.HandlerFunc (func (w http.ResponseWriter , r *http.Request ) {
106+ if r.Method == " POST" && r.URL .Path == " /shutdown" {
107+ cancel ()
108+ return
109+ }
110+ // ...
111+ }),
112+ }
113+ keeper.OnShuttingDown (func () { server.Shutdown (context.Background ()) })
114+ go server.ListenAndServe ()
123115
124116 // This will block until every HoldToken is released or the MaxHoldTime is reached.
125117 keeper.Wait ()
You can’t perform that action at this time.
0 commit comments