ch14.5
This commit is contained in:
@@ -36,7 +36,18 @@ func (app *application) serve() error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
|
||||
shutdownError <- srv.Shutdown(ctx)
|
||||
err := srv.Shutdown(ctx)
|
||||
if err != nil {
|
||||
shutdownError <- err
|
||||
}
|
||||
|
||||
app.logger.PrintInfo("completing background tasks", map[string]string{
|
||||
"addr": srv.Addr,
|
||||
})
|
||||
|
||||
app.wg.Wait()
|
||||
shutdownError <- nil
|
||||
|
||||
}()
|
||||
|
||||
app.logger.PrintInfo("starting server", map[string]string{
|
||||
@@ -49,13 +60,14 @@ func (app *application) serve() error {
|
||||
return err
|
||||
}
|
||||
|
||||
app.logger.PrintInfo("stopped server", map[string]string{
|
||||
"addr": srv.Addr,
|
||||
})
|
||||
|
||||
err = <-shutdownError
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
app.logger.PrintInfo("stopped server", map[string]string{
|
||||
"addr": srv.Addr,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user