net.unbound: Remove compat for missing promises (pre-0.11)

Code existed in a separate project before merged into Prosody, so
util.promise was not always around.
This commit is contained in:
Kim Alvefur 2020-06-25 18:20:51 +02:00
parent 9be5cb3fbd
commit 02c3cc978d

View file

@ -16,7 +16,7 @@ local noop = function() end;
local log = require "util.logger".init("unbound"); local log = require "util.logger".init("unbound");
local net_server = require "net.server"; local net_server = require "net.server";
local libunbound = require"lunbound"; local libunbound = require"lunbound";
local have_promise, promise = pcall(require, "util.promise"); local promise = require"util.promise";
local gettime = require"socket".gettime; local gettime = require"socket".gettime;
local dns_utils = require"util.dns"; local dns_utils = require"util.dns";
@ -178,21 +178,18 @@ local _M = {
}; };
}; };
local lookup_promise; local function lookup_promise(_, qname, qtype, qclass)
if have_promise then return promise.new(function (resolve, reject)
function lookup_promise(_, qname, qtype, qclass) local function callback(answer, err)
return promise.new(function (resolve, reject) if err then
local function callback(answer, err) return reject(err);
if err then else
return reject(err); return resolve(answer);
else
return resolve(answer);
end
end end
local ret, err = lookup(callback, qname, qtype, qclass) end
if not ret then reject(err); end local ret, err = lookup(callback, qname, qtype, qclass)
end); if not ret then reject(err); end
end end);
end end
local wrapper = { local wrapper = {