diff options
author | Matthew Wild <mwild1@gmail.com> | 2020-01-24 13:50:02 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2020-01-24 13:50:02 +0000 |
commit | 5d9270502bcf1309d9718cb55873292296eebf70 (patch) | |
tree | 2ecb5446187e7d04b1884565cdb6a4c44ea4af04 /net | |
parent | 6ab4b844637e4a558acca967b601cdbb909d5f99 (diff) | |
download | prosody-5d9270502bcf1309d9718cb55873292296eebf70.tar.gz prosody-5d9270502bcf1309d9718cb55873292296eebf70.zip |
net.adns: Add :lookup_promise() method
Diffstat (limited to 'net')
-rw-r--r-- | net/adns.lua | 13 |
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); |