util.promise: Switch order of parameters to join()

This saves awkward fiddlery with varargs and also echoes the
signature of pcall/xpcall.
This commit is contained in:
Matthew Wild 2021-03-25 15:08:22 +00:00
parent fec0d44e89
commit d1ccd87d55
2 changed files with 4 additions and 6 deletions

View file

@ -498,10 +498,10 @@ describe("util.promise", function ()
local res1, res2;
local p1, p2 = promise.new(function (resolve) r1 = resolve end), promise.new(function (resolve) r2 = resolve end);
local p = promise.join(p1, p2, function (_res1, _res2)
local p = promise.join(function (_res1, _res2)
res1, res2 = _res1, _res2;
return promise.resolve("works");
end);
end, p1, p2);
local result;
local cb = spy.new(function (v)

View file

@ -146,12 +146,10 @@ local function all_settled(promises)
end);
end
local function join(...)
local function join(handler, ...)
local promises, n = { ... }, select("#", ...);
local handler = promises[n];
promises[n] = nil;
return all(promises):next(function (results)
return handler(unpack(results, 1, n - 1));
return handler(unpack(results, 1, n));
end);
end