Software /
code /
prosody
Comparison
net/unbound.lua @ 10968:23ae55cbbeaf
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 25 Jun 2020 18:20:51 +0200 |
parent | 10967:67aabf83230b |
child | 11248:a1aecd8cf7ee |
comparison
equal
deleted
inserted
replaced
10967:67aabf83230b | 10968:23ae55cbbeaf |
---|---|
14 local noop = function() end; | 14 local noop = function() end; |
15 | 15 |
16 local log = require "util.logger".init("unbound"); | 16 local log = require "util.logger".init("unbound"); |
17 local net_server = require "net.server"; | 17 local net_server = require "net.server"; |
18 local libunbound = require"lunbound"; | 18 local libunbound = require"lunbound"; |
19 local have_promise, promise = pcall(require, "util.promise"); | 19 local promise = require"util.promise"; |
20 | 20 |
21 local gettime = require"socket".gettime; | 21 local gettime = require"socket".gettime; |
22 local dns_utils = require"util.dns"; | 22 local dns_utils = require"util.dns"; |
23 local classes, types, errors = dns_utils.classes, dns_utils.types, dns_utils.errors; | 23 local classes, types, errors = dns_utils.classes, dns_utils.types, dns_utils.errors; |
24 local parsers = dns_utils.parsers; | 24 local parsers = dns_utils.parsers; |
176 types = types; | 176 types = types; |
177 classes = classes; | 177 classes = classes; |
178 }; | 178 }; |
179 }; | 179 }; |
180 | 180 |
181 local lookup_promise; | 181 local function lookup_promise(_, qname, qtype, qclass) |
182 if have_promise then | 182 return promise.new(function (resolve, reject) |
183 function lookup_promise(_, qname, qtype, qclass) | 183 local function callback(answer, err) |
184 return promise.new(function (resolve, reject) | 184 if err then |
185 local function callback(answer, err) | 185 return reject(err); |
186 if err then | 186 else |
187 return reject(err); | 187 return resolve(answer); |
188 else | |
189 return resolve(answer); | |
190 end | |
191 end | 188 end |
192 local ret, err = lookup(callback, qname, qtype, qclass) | 189 end |
193 if not ret then reject(err); end | 190 local ret, err = lookup(callback, qname, qtype, qclass) |
194 end); | 191 if not ret then reject(err); end |
195 end | 192 end); |
196 end | 193 end |
197 | 194 |
198 local wrapper = { | 195 local wrapper = { |
199 lookup = function (_, callback, qname, qtype, qclass) | 196 lookup = function (_, callback, qname, qtype, qclass) |
200 return lookup(callback, qname, qtype, qclass) | 197 return lookup(callback, qname, qtype, qclass) |