Skip to content

Commit ba5d3d8

Browse files
committed
update: README.md
1 parent 7c85068 commit ba5d3d8

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

README.md

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff 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()

0 commit comments

Comments
 (0)