Changeset

11486:78d843faaffc

util.promise: Switch order of parameters to join() This saves awkward fiddlery with varargs and also echoes the signature of pcall/xpcall.
author Matthew Wild <mwild1@gmail.com>
date Thu, 25 Mar 2021 15:08:22 +0000
parents 11485:7d42ed3a8a40
children 11487:b104c10ffce7
files spec/util_promise_spec.lua util/promise.lua
diffstat 2 files changed, 4 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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