Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: mention defaults in option docs #1013

Merged
merged 1 commit into from Jul 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions nats.go
Expand Up @@ -331,10 +331,12 @@ type Options struct {
// MaxReconnect sets the number of reconnect attempts that will be
// tried before giving up. If negative, then it will never give up
// trying to reconnect.
// Defaults to 60.
MaxReconnect int

// ReconnectWait sets the time to backoff after attempting a reconnect
// to a server that we were already connected to previously.
// Defaults to 2s.
ReconnectWait time.Duration

// CustomReconnectDelayCB is invoked after the library tried every
Expand All @@ -347,16 +349,20 @@ type Options struct {

// ReconnectJitter sets the upper bound for a random delay added to
// ReconnectWait during a reconnect when no TLS is used.
// Defaults to 100ms.
ReconnectJitter time.Duration

// ReconnectJitterTLS sets the upper bound for a random delay added to
// ReconnectWait during a reconnect when TLS is used.
// Defaults to 1s.
ReconnectJitterTLS time.Duration

// Timeout sets the timeout for a Dial operation on a connection.
// Defaults to 2s.
Timeout time.Duration

// DrainTimeout sets the timeout for a Drain Operation to complete.
// Defaults to 30s.
DrainTimeout time.Duration

// FlusherTimeout is the maximum time to wait for write operations
Expand All @@ -365,10 +371,12 @@ type Options struct {

// PingInterval is the period at which the client will be sending ping
// commands to the server, disabled if 0 or negative.
// Defaults to 2m.
PingInterval time.Duration

// MaxPingsOut is the maximum number of pending ping commands that can
// be awaiting a response before raising an ErrStaleConnection error.
// Defaults to 2.
MaxPingsOut int

// ClosedCB sets the closed handler that is called when a client will
Expand Down Expand Up @@ -401,12 +409,14 @@ type Options struct {

// ReconnectBufSize is the size of the backing bufio during reconnect.
// Once this has been exhausted publish operations will return an error.
// Defaults to 8388608 bytes (8MB).
ReconnectBufSize int

// SubChanLen is the size of the buffered channel used between the socket
// Go routine and the message delivery for SyncSubscriptions.
// NOTE: This does not affect AsyncSubscriptions which are
// dictated by PendingLimits()
// Defaults to 65536.
SubChanLen int

// UserJWT sets the callback handler that will fetch a user's JWT.
Expand Down Expand Up @@ -861,6 +871,7 @@ func NoEcho() Option {
}

// ReconnectWait is an Option to set the wait time between reconnect attempts.
// Defaults to 2s.
func ReconnectWait(t time.Duration) Option {
return func(o *Options) error {
o.ReconnectWait = t
Expand All @@ -869,6 +880,7 @@ func ReconnectWait(t time.Duration) Option {
}

// MaxReconnects is an Option to set the maximum number of reconnect attempts.
// Defaults to 60.
func MaxReconnects(max int) Option {
return func(o *Options) error {
o.MaxReconnect = max
Expand All @@ -877,6 +889,7 @@ func MaxReconnects(max int) Option {
}

// ReconnectJitter is an Option to set the upper bound of a random delay added ReconnectWait.
// Defaults to 100ms and 1s, respectively.
func ReconnectJitter(jitter, jitterForTLS time.Duration) Option {
return func(o *Options) error {
o.ReconnectJitter = jitter
Expand All @@ -895,6 +908,7 @@ func CustomReconnectDelay(cb ReconnectDelayHandler) Option {
}

// PingInterval is an Option to set the period for client ping commands.
// Defaults to 2m.
func PingInterval(t time.Duration) Option {
return func(o *Options) error {
o.PingInterval = t
Expand All @@ -904,6 +918,7 @@ func PingInterval(t time.Duration) Option {

// MaxPingsOutstanding is an Option to set the maximum number of ping requests
// that can go unanswered by the server before closing the connection.
// Defaults to 2.
func MaxPingsOutstanding(max int) Option {
return func(o *Options) error {
o.MaxPingsOut = max
Expand All @@ -912,6 +927,7 @@ func MaxPingsOutstanding(max int) Option {
}

// ReconnectBufSize sets the buffer size of messages kept while busy reconnecting.
// Defaults to 8388608 bytes (8MB).
func ReconnectBufSize(size int) Option {
return func(o *Options) error {
o.ReconnectBufSize = size
Expand All @@ -920,6 +936,7 @@ func ReconnectBufSize(size int) Option {
}

// Timeout is an Option to set the timeout for Dial on a connection.
// Defaults to 2s.
func Timeout(t time.Duration) Option {
return func(o *Options) error {
o.Timeout = t
Expand All @@ -936,6 +953,7 @@ func FlusherTimeout(t time.Duration) Option {
}

// DrainTimeout is an Option to set the timeout for draining a connection.
// Defaults to 30s.
func DrainTimeout(t time.Duration) Option {
return func(o *Options) error {
o.DrainTimeout = t
Expand Down Expand Up @@ -1078,6 +1096,7 @@ func Nkey(pubKey string, sigCB SignatureHandler) Option {

// SyncQueueLen will set the maximum queue len for the internal
// channel used for SubscribeSync().
// Defaults to 65536.
func SyncQueueLen(max int) Option {
return func(o *Options) error {
o.SubChanLen = max
Expand Down