asyncify the vultr and DO backend

This commit is contained in:
Girish Ramakrishnan
2022-02-04 09:37:02 -08:00
parent bd4097098d
commit 856b23d940
6 changed files with 203 additions and 311 deletions
+2 -2
View File
@@ -19,7 +19,7 @@ async function resolve(hostname, rrtype, options) {
assert(options && typeof options === 'object');
const defaultOptions = { server: '127.0.0.1', timeout: 5000 }; // unbound runs on 127.0.0.1
const resolver = new dns.Resolver();
const resolver = new dns.promises.Resolver();
options = _.extend({ }, defaultOptions, options);
// Only use unbound on a Cloudron
@@ -28,7 +28,7 @@ async function resolve(hostname, rrtype, options) {
// should callback with ECANCELLED but looks like we might hit https://github.com/nodejs/node/issues/14814
const timerId = setTimeout(resolver.cancel.bind(resolver), options.timeout || 5000);
const [error, result] = safe(resolver.resolve(hostname, rrtype));
const [error, result] = await safe(resolver.resolve(hostname, rrtype));
clearTimeout(timerId);
if (error && error.code === 'ECANCELLED') error.code = 'TIMEOUT';