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