Skip to content

Commit

Permalink
Merge pull request #32 from acoshift/apps/wait
Browse files Browse the repository at this point in the history
apps: wait each app on graceful
  • Loading branch information
acoshift committed May 18, 2018
2 parents 9c2f2ed + fe7d2ba commit 89e5305
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,15 @@ func (gs *GracefulShutdownApps) ListenAndServe() error {
wg.Add(1)
go func() {
ctx := shutdownCtx
if app.gracefulShutdown != nil && app.gracefulShutdown.timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(shutdownCtx, app.gracefulShutdown.timeout)
defer cancel()
if app.gracefulShutdown != nil {
if app.gracefulShutdown.wait > 0 {
time.Sleep(app.gracefulShutdown.wait)
}
if app.gracefulShutdown.timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(shutdownCtx, app.gracefulShutdown.timeout)
defer cancel()
}
}
err := app.srv.Shutdown(ctx)
if err != nil {
Expand Down

0 comments on commit 89e5305

Please sign in to comment.