Selaa lähdekoodia

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
ffhelicopter 6 vuotta sitten
vanhempi
commit
90587c7787
2 muutettua tiedostoa jossa 10 lisäystä ja 0 poistoa
  1. 5 0
      README.md
  2. 5 0
      examples/graceful-shutdown/graceful-shutdown/server.go

+ 5 - 0
README.md

@@ -1673,6 +1673,11 @@ func main() {
 	if err := srv.Shutdown(ctx); err != nil {
 	if err := srv.Shutdown(ctx); err != nil {
 		log.Fatal("Server Shutdown:", err)
 		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")
 	log.Println("Server exiting")
 }
 }
 ```
 ```

+ 5 - 0
examples/graceful-shutdown/graceful-shutdown/server.go

@@ -48,5 +48,10 @@ func main() {
 	if err := srv.Shutdown(ctx); err != nil {
 	if err := srv.Shutdown(ctx); err != nil {
 		log.Fatal("Server Shutdown:", err)
 		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")
 	log.Println("Server exiting")
 }
 }