Comparison

net/resolvers/chain.lua @ 12204:7c397a49d163

net.resolvers.chain: A resolver for combining other resolvers Say if you wanted to try both _xmpp and _xmpps services
author Kim Alvefur <zash@zash.se>
date Fri, 21 Jan 2022 17:56:20 +0100
comparison
equal deleted inserted replaced
12203:320de3e4b579 12204:7c397a49d163
1
2 local methods = {};
3 local resolver_mt = { __index = methods };
4
5 -- Find the next target to connect to, and
6 -- pass it to cb()
7 function methods:next(cb)
8 if self.resolvers then
9 if not self.resolver then
10 if #self.resolvers == 0 then
11 cb(nil);
12 return;
13 end
14 local next_resolver = table.remove(self.resolvers, 1);
15 self.resolver = next_resolver;
16 end
17 self.resolver:next(function (...)
18 if self.resolver then
19 self.last_error = self.resolver.last_error;
20 end
21 if ... == nil then
22 self.resolver = nil;
23 self:next(cb);
24 else
25 cb(...);
26 end
27 end);
28 return;
29 end
30 end
31
32 local function new(resolvers)
33 return setmetatable({ resolvers = resolvers }, resolver_mt);
34 end
35
36 return {
37 new = new;
38 };