[#1031] morph: Add maxConnPerHost option

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-12-15 21:04:36 +03:00 committed by Alex Vanin
parent 63e035bd8a
commit c49e53ba9d
3 changed files with 18 additions and 3 deletions

View file

@ -32,12 +32,15 @@ type cfg struct {
extraEndpoints []string
maxConnPerHost int
singleCli *client.Client // neo-go client for single client mode
}
const (
defaultDialTimeout = 5 * time.Second
defaultWaitInterval = 500 * time.Millisecond
defaultDialTimeout = 5 * time.Second
defaultWaitInterval = 500 * time.Millisecond
defaultMaxConnPerHost = 10
)
func defaultConfig() *cfg {
@ -49,6 +52,7 @@ func defaultConfig() *cfg {
signer: &transaction.Signer{
Scopes: transaction.Global,
},
maxConnPerHost: defaultMaxConnPerHost,
}
}
@ -166,6 +170,15 @@ func WithExtraEndpoints(endpoints []string) Option {
}
}
// WithMaxConnectionPerHost returns a client constructor
// option that specifies Neo client's maximum opened
// connection per one host.
func WithMaxConnectionPerHost(m int) Option {
return func(c *cfg) {
c.maxConnPerHost = m
}
}
// WithSingleClient returns a client constructor option
// that specifies single neo-go client and forces Client
// to use it and only it for requests.