Skip to content

Commit

Permalink
app: add callback after shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
agungdwiprasetyo committed Jul 5, 2024
1 parent b64631e commit 88bdd4d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions codebase/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ func SetShutdownTimeout(shutdownTimeout time.Duration) Option {
}
}

// SetAfterShutdown set do after shutdown
func SetAfterShutdown(do func()) Option {
return func(a *App) {
a.afterShutdown = do
}
}

// SetQuitSignalTrigger option
func SetQuitSignalTrigger(quitSignalTriggers []os.Signal) Option {
return func(a *App) {
Expand All @@ -33,6 +40,7 @@ func SetQuitSignalTrigger(quitSignalTriggers []os.Signal) Option {
// App service
type App struct {
done chan struct{}
afterShutdown func()
shutdownTimeout time.Duration
quitSignal chan os.Signal
quitSignalTriggers []os.Signal
Expand Down Expand Up @@ -102,6 +110,9 @@ func (a *App) shutdown() {
ctx, cancel := context.WithTimeout(context.Background(), a.shutdownTimeout)
defer func() {
cancel()
if a.afterShutdown != nil {
a.afterShutdown()
}
a.done <- struct{}{}
}()

Expand Down

0 comments on commit 88bdd4d

Please sign in to comment.