@@ -16,9 +16,9 @@ type ApplicationConfig struct {
1616}
1717
1818type Application struct {
19+ serviceState
1920 fasthttpService FasthttpService
2021 Configuration ApplicationConfig
21- running bool
2222 done chan bool
2323 signals chan os.Signal
2424}
@@ -33,6 +33,8 @@ func NewApplication(config ApplicationConfig, router Router) *Application {
3333 }
3434
3535 app .fasthttpService .Server .Handler = router .Handler ()
36+ app .done = make (chan bool , 1 )
37+ app .signals = make (chan os.Signal , 1 )
3638
3739 return app
3840}
@@ -57,17 +59,14 @@ func (app *Application) Start() error {
5759 return err
5860 }
5961
60- app .done = make (chan bool , 1 )
61- app .signals = make (chan os.Signal , 1 )
62-
6362 go func () {
6463 signal .Notify (app .signals , syscall .SIGINT , syscall .SIGTERM )
6564 if _ , ok := <- app .signals ; ok {
6665 app .Stop ()
6766 }
6867 }()
6968
70- app .running = true
69+ app .setRunning ( true )
7170 if err := app .fasthttpService .Start (); err != nil {
7271 return err
7372 }
@@ -77,14 +76,14 @@ func (app *Application) Start() error {
7776}
7877
7978func (app * Application ) Stop () error {
80- if app .running {
79+ if app .isRunning () {
8180 defer func () {
8281 if app .Configuration .ServiceStarter != nil {
8382 app .Configuration .ServiceStarter .Stop (true )
8483 }
85- close (app .signals )
86- close ( app .done )
87- app .running = false
84+ signal . Stop (app .signals )
85+ app .done <- true
86+ app .setRunning ( false )
8887 }()
8988 return app .fasthttpService .Stop ()
9089 }
0 commit comments