Update: examples/graceful-shutdown/server.go (#1530)

* Update server.go

It's necessary that  catching  ctx.Done()

* Update server.go

* Update server.go

* Update README.md

* Update README.md
This commit is contained in:
ffhelicopter 2019-02-20 13:24:29 +08:00 committed by 田欧
parent fece76d93f
commit 90587c7787
2 changed files with 10 additions and 0 deletions

View File

@ -1673,6 +1673,11 @@ func main() {
if err := srv.Shutdown(ctx); err != nil {
log.Fatal("Server Shutdown:", err)
}
// catching ctx.Done(). timeout of 5 seconds.
select {
case <-ctx.Done():
log.Println("timeout of 5 seconds.")
}
log.Println("Server exiting")
}
```

View File

@ -48,5 +48,10 @@ func main() {
if err := srv.Shutdown(ctx); err != nil {
log.Fatal("Server Shutdown:", err)
}
// catching ctx.Done(). timeout of 5 seconds.
select {
case <-ctx.Done():
log.Println("timeout of 5 seconds.")
}
log.Println("Server exiting")
}