From 139bc6e31fe2b3ddd1fb18c216268219ef91e686 Mon Sep 17 00:00:00 2001 From: Noah <130611693+upupnoah@users.noreply.github.com> Date: Sun, 4 Feb 2024 00:38:24 +0800 Subject: [PATCH] Update graceful-restart-or-stop.md Only one case, use < -ctx. Done () directly. --- content/en/docs/examples/graceful-restart-or-stop.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/content/en/docs/examples/graceful-restart-or-stop.md b/content/en/docs/examples/graceful-restart-or-stop.md index aae74ebd8..69079912c 100644 --- a/content/en/docs/examples/graceful-restart-or-stop.md +++ b/content/en/docs/examples/graceful-restart-or-stop.md @@ -24,6 +24,7 @@ An alternative to endless: If you are using Go 1.8, you may not need to use this library! Consider using http.Server's built-in [Shutdown()](https://golang.org/pkg/net/http/#Server.Shutdown) method for graceful shutdowns. See the full [graceful-shutdown](https://github.com/gin-gonic/examples/tree/master/graceful-shutdown) example with gin. ```go +//go:build go1.8 // +build go1.8 package main @@ -75,10 +76,12 @@ func main() { log.Fatal("Server Shutdown:", err) } // catching ctx.Done(). timeout of 5 seconds. - select { - case <-ctx.Done(): - log.Println("timeout of 5 seconds.") - } + // select { + // case <-ctx.Done(): + // log.Println("timeout of 5 seconds.") + // } + <-ctx.Done() + log.Println("timeout of 5 seconds.") log.Println("Server exiting") } ```