You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
687 B

4 years ago
  1. var dns = require('dns');
  2. var retry = require('../lib/retry');
  3. function faultTolerantResolve(address, cb) {
  4. var opts = {
  5. retries: 2,
  6. factor: 2,
  7. minTimeout: 1 * 1000,
  8. maxTimeout: 2 * 1000,
  9. randomize: true
  10. };
  11. var operation = retry.operation(opts);
  12. operation.attempt(function(currentAttempt) {
  13. dns.resolve(address, function(err, addresses) {
  14. if (operation.retry(err)) {
  15. return;
  16. }
  17. cb(operation.mainError(), operation.errors(), addresses);
  18. });
  19. });
  20. }
  21. faultTolerantResolve('nodejs.org', function(err, errors, addresses) {
  22. console.warn('err:');
  23. console.log(err);
  24. console.warn('addresses:');
  25. console.log(addresses);
  26. });