Last active
August 29, 2015 14:01
-
-
Save srijs/3843bd91079726dd28dd to your computer and use it in GitHub Desktop.
Using Q with node-retry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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