Skip to content

Instantly share code, notes, and snippets.

@srijs
Last active August 29, 2015 14:01
Show Gist options
  • Save srijs/3843bd91079726dd28dd to your computer and use it in GitHub Desktop.
Save srijs/3843bd91079726dd28dd to your computer and use it in GitHub Desktop.
Using Q with node-retry
module.exports = function attemptQ (f) {
var d = require('q').defer();
this.attempt(function (i) {
f(i).then(d.resolve.bind(d), function (e) {
this.retry(e) || d.reject(this.mainError());
}.bind(this));
});
return d.promise;
};
var retry = require('retry'),
attempt = require('attemptq');
attempt.call(retry.operation({retries: 5}), doStuff)
.then(function (result) {
console.log('Result: ' + result);
})
.fail(function (err) {
console.error('Error:' + err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment