Skip to content

Commit

Permalink
Add retry options
Browse files Browse the repository at this point in the history
  • Loading branch information
nsurfer committed Mar 12, 2021
1 parent 4b55d13 commit 379ce6f
Show file tree
Hide file tree
Showing 3 changed files with 305 additions and 195 deletions.
20 changes: 20 additions & 0 deletions js.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ type jsOpts struct {
wait time.Duration
// Signals only direct access and no API access.
direct bool

maxTries int
retryBackoff time.Duration
}

const defaultRequestWait = 5 * time.Second
Expand Down Expand Up @@ -192,6 +195,23 @@ func DirectOnly() JSOpt {
})
}

// MaxRetries indicates the number of times to retry a failed operation. -1
// means infinite retries.
type MaxRetries int

func (v MaxRetries) configureJSContext(opts *jsOpts) error {
opts.maxTries = int(v)
return nil
}

// RetryBackoff indicates how long to wait between retries.
type RetryBackoff time.Duration

func (v RetryBackoff) configureJSContext(opts *jsOpts) error {
opts.retryBackoff = time.Duration(v)
return nil
}

func (js *js) apiSubj(subj string) string {
if js.opts.pre == _EMPTY_ {
return subj
Expand Down
Loading

0 comments on commit 379ce6f

Please sign in to comment.