Diff

util/promise.lua @ 12749:eb9814372c54

util.promise: Remove some redundant checks, add tests confirming redundancy This lines don't appear to do anything useful, and all tests pass when they are removed. Discovered via mutation testing. I added extra tests to exercise this code, because I wasn't certain that there were no side-effects caused by removal. Everything appears to be fine, thanks to the "pending" check at the start of promise_settle().
author Matthew Wild <mwild1@gmail.com>
date Fri, 07 Oct 2022 17:43:26 +0100
parent 12589:39ae08180c81
child 12750:c882d2460bb1
line wrap: on
line diff
--- a/util/promise.lua	Fri Oct 07 17:01:35 2022 +0100
+++ b/util/promise.lua	Fri Oct 07 17:43:26 2022 +0100
@@ -57,9 +57,7 @@
 end
 
 local function new_resolve_functions(p)
-	local resolved = false;
 	local function _resolve(v)
-		if resolved then return; end
 		resolved = true;
 		if is_promise(v) then
 			v:next(new_resolve_functions(p));
@@ -69,8 +67,6 @@
 
 	end
 	local function _reject(e)
-		if resolved then return; end
-		resolved = true;
 		if promise_settle(p, "rejected", next_rejected, p._pending_on_rejected, e) then
 			p.reason = e;
 		end