add gracefultimeout in server #303
@ -65,6 +65,8 @@ type Options struct {
|
||||
DeregisterAttempts int
|
||||
// Hooks may contains HandleWrapper or Server func wrapper
|
||||
Hooks options.Hooks
|
||||
// GracefulTimeout timeout for graceful stop server
|
||||
GracefulTimeout time.Duration
|
||||
}
|
||||
|
||||
// NewOptions returns new options struct with default or passed values
|
||||
@ -84,6 +86,7 @@ func NewOptions(opts ...options.Option) Options {
|
||||
Name: DefaultName,
|
||||
Version: DefaultVersion,
|
||||
ID: id.Must(),
|
||||
GracefulTimeout: DefaultGracefulTimeout,
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
@ -162,6 +165,12 @@ func Listener(nl net.Listener) options.Option {
|
||||
}
|
||||
}
|
||||
|
||||
func GracefulTimeout(t time.Duration) options.Option {
|
||||
return func(src interface{}) error {
|
||||
return options.Set(src, t, ".GracefulTimeout")
|
||||
}
|
||||
}
|
||||
|
||||
// HandleOptions struct
|
||||
type HandleOptions struct {
|
||||
// Context holds external options
|
||||
|
@ -32,6 +32,8 @@ var (
|
||||
DefaultMaxMsgRecvSize = 1024 * 1024 * 4 // 4Mb
|
||||
// DefaultMaxMsgSendSize holds default max send size
|
||||
DefaultMaxMsgSendSize = 1024 * 1024 * 4 // 4Mb
|
||||
// DefaultGracefulTimeout default time for graceful stop
|
||||
DefaultGracefulTimeout = 5 * time.Second
|
||||
)
|
||||
|
||||
// Server is a simple micro server abstraction
|
||||
|
Loading…
Reference in New Issue
Block a user