Skip to content

Commit 074a3a5

Browse files
committed
go doc 修正
1 parent d08a910 commit 074a3a5

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

cmd/example/main.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ func (s *ExampleServer) Serve(ctx context.Context) error {
3636
}
3737

3838
func (s *ExampleServer) Shutdown(ctx context.Context) error {
39-
fmt.Println("example shutdown")
4039
close(s.done)
4140
select {
4241
case <-s.shutdowned:
42+
fmt.Println("example shutdown")
4343
return nil
4444
case <-ctx.Done():
4545
if err := ctx.Err(); errors.Is(err, context.DeadlineExceeded) {
46-
return context.DeadlineExceeded
46+
return errors.Join(errors.New("failed to shutdown example"), context.DeadlineExceeded)
4747
}
4848
return context.Canceled
4949
}
@@ -72,14 +72,14 @@ func (s *ExampleBlockingServer) Serve(ctx context.Context) error {
7272
}
7373

7474
func (s *ExampleBlockingServer) Shutdown(ctx context.Context) error {
75-
fmt.Println("example blocking shutdown")
7675
close(s.done)
7776
select {
7877
case <-s.shutdowned:
78+
fmt.Println("example blocking shutdown")
7979
return nil
8080
case <-ctx.Done():
8181
if err := ctx.Err(); errors.Is(err, context.DeadlineExceeded) {
82-
return context.DeadlineExceeded
82+
return errors.Join(errors.New("failed to shutdown blocking example"), context.DeadlineExceeded)
8383
}
8484
return context.Canceled
8585
}

graceful.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ type Servers struct {
2222
Servers []Server
2323
}
2424

25-
// gracefulOpts represents configuration parameters for the Server.
26-
// In default, gracefulOpts.Signals is []os.Signal{syscall.SIGINT, syscall.SIGTERM} and gracefulOpts.ShutdownTimeout is 0.
2725
type gracefulOpts struct {
2826
Signals []os.Signal
2927
ShutdownTimeout time.Duration
@@ -39,18 +37,18 @@ func defaultGracefulOpts() gracefulOpts {
3937
// Option applies an option to the Server.
4038
type Option func(*gracefulOpts)
4139

42-
// GracefulSignals sets signals to be received.
40+
// GracefulSignals sets signals to be received. Default is syscall.SIGINT & syscall.SIGTERM.
4341
func GracefulSignals(signals ...os.Signal) Option {
4442
return func(o *gracefulOpts) { o.Signals = signals }
4543
}
4644

47-
// GracefulShutdownTimeout sets timeout for shutdown.
45+
// GracefulShutdownTimeout sets timeout for shutdown. Default is 0.
4846
func GracefulShutdownTimeout(timeout time.Duration) Option {
4947
return func(o *gracefulOpts) { o.ShutdownTimeout = timeout }
5048
}
5149

52-
// Graceful runs all servers contained in s, then waits signals.
53-
// When receive an expected signal (in default, os.Interrupt), s stops all servers gracefully.
50+
// Graceful runs all servers contained in `s`, then waits signals.
51+
// When receive an expected signal (in default, syscall.SIGINT & syscall.SIGTERM), `s` stops all servers gracefully.
5452
func (s Servers) Graceful(ctx context.Context, options ...Option) error {
5553
opts := defaultGracefulOpts()
5654
for _, f := range options {

0 commit comments

Comments
 (0)