Skip to content

Commit

Permalink
fix: tidy notify os interrupt signals
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Jul 31, 2024
1 parent 83495e2 commit aa15af5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cmd/soft/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ var (
}
}

lch := make(chan error, 1)
done := make(chan os.Signal, 1)
doneOnce := sync.OnceFunc(func() { close(done) })

lch := make(chan error, 1)
signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)

// This endpoint is added for testing purposes
// It allows us to stop the server from the test suite.
Expand All @@ -102,11 +103,10 @@ var (
}

go func() {
defer doneOnce()
lch <- s.Start()
doneOnce()
}()

signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
<-done

ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
Expand Down

0 comments on commit aa15af5

Please sign in to comment.