tim-kos/node-retry

Documentation is not entirely clear

ghostsquad opened this issue · 3 comments

The first example provided in the documentation contains too much information for me wrap my mind around what's going on, and how I properly write a retry.

My questions:
given:

retry = require 'retry'
operation = retry.operation
operation.attempt (curAttempt) ->
   # do some work
   # what goes here to indicate that I failed and need to retry?

ok, so after a bit more testing, I believe it's as simple as:

# simple example that retries after catching an error
operation.attempt (curAttempt) ->
  try
    console.log 'doing foo. attempt ##{curAttemp}'
    # do something here, that throws an error
  catch err
    operation.retry(err)

# simple example that retries after fail flag is set
operation.attempt (curAttempt) ->
  console.log 'doing foo. attempt ##{curAttemp}'
  err = null
  # do something here, set failed var on condition
  if failed
    err = new Error 'something went wrong'
  operation.retry(err)

I'll submit a pull request if you think this is a better example of how to use this framework.

Hey @ghostsquad

Okay sounds good, please submit a PR.

Closing this. Please re-open this once you have sent the PR.