Skip to content

Commit

Permalink
Merge pull request #1013 from costela/docs/mention-defaults-in-option…
Browse files Browse the repository at this point in the history
…-docs

docs: mention defaults in option docs
  • Loading branch information
kozlovic committed Jul 12, 2022
2 parents 8a4b9f4 + 891dbe3 commit 2d22c44
Showing 1 changed file with 19 additions and 0 deletions.
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

0 comments on commit 2d22c44

Please sign in to comment.