Documentation is not entirely clear
ghostsquad opened this issue · 3 comments
ghostsquad commented
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?
ghostsquad commented
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.
tim-kos commented
Hey @ghostsquad
Okay sounds good, please submit a PR.
tim-kos commented
Closing this. Please re-open this once you have sent the PR.