aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2020-01-24 13:50:02 +0000
committerMatthew Wild <mwild1@gmail.com>2020-01-24 13:50:02 +0000
commit5ac8804435ba7378a39d6fd213da35c57165c483 (patch)
tree2ecb5446187e7d04b1884565cdb6a4c44ea4af04 /net
parent9782727301205d85ca58a88f9ab356600bda4013 (diff)
downloadprosody-5ac8804435ba7378a39d6fd213da35c57165c483.tar.gz
prosody-5ac8804435ba7378a39d6fd213da35c57165c483.zip
net.adns: Add :lookup_promise() method
Diffstat (limited to 'net')
-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);