aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/adns.lua13
1 files changed, 13 insertions, 0 deletions
diff --git a/net/adns.lua b/net/adns.lua
index d7266958..bf6c11ab 100644
--- a/net/adns.lua
+++ b/net/adns.lua
@@ -8,6 +8,7 @@
local server = require "net.server";
local new_resolver = require "net.dns".resolver;
+local promise = require "util.promise";
local log = require "util.logger".init("adns");
@@ -91,6 +92,18 @@ function async_resolver_methods:lookup(handler, qname, qtype, qclass)
end)(resolver:peek(qname, qtype, qclass));
end
+function async_resolver_methods:lookup_promise(qname, qtype, qclass)
+ return promise.new(function (resolve, reject)
+ local function handler(answer)
+ if not answer then
+ return reject();
+ end
+ resolve(answer);
+ end
+ self:lookup(handler, qname, qtype, qclass);
+ end);
+end
+
function query_methods:cancel(call_handler, reason) -- luacheck: ignore 212/reason
log("warn", "Cancelling DNS lookup for %s", self[4]);
self[1].cancel(self[2], self[3], self[4], self[5], call_handler);