# HG changeset patch # User Matthew Wild # Date 1616684902 0 # Node ID 78d843faaffce3ba6cb3a3ec4bda60f273730de1 # Parent 7d42ed3a8a40c15d28ab2ae2675d6a1b8da2b05b util.promise: Switch order of parameters to join() This saves awkward fiddlery with varargs and also echoes the signature of pcall/xpcall. diff -r 7d42ed3a8a40 -r 78d843faaffc spec/util_promise_spec.lua --- a/spec/util_promise_spec.lua Thu Mar 25 14:32:32 2021 +0000 +++ b/spec/util_promise_spec.lua Thu Mar 25 15:08:22 2021 +0000 @@ -498,10 +498,10 @@ 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) diff -r 7d42ed3a8a40 -r 78d843faaffc util/promise.lua --- a/util/promise.lua Thu Mar 25 14:32:32 2021 +0000 +++ b/util/promise.lua Thu Mar 25 15:08:22 2021 +0000 @@ -146,12 +146,10 @@ 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