From 9c33d03245ab2794c76c16eb313e64c482d321ed Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Sat, 3 Sep 2022 01:49:54 +0200 Subject: [PATCH] [MIRROR] [Lua] You can now `await` expensive non-sleeping procs. [MDB IGNORE] (#15962) * [Lua] You can now `await` expensive non-sleeping procs. (#69570) When trying to run getFlatIcon using lua scripting, I discovered that it was so expensive that, for certain atoms like complex humans, there is no way it will complete within the lua execution limit. While Mothblocks would suggest just raising the execution limit, the idea leaves a bad taste in my mouth due to the possibility of a script causing extreme lag by consistently overrunning the BYOND tick. I instead elected to make /datum/auxtools_promise sleep once before invoking its assigned proc, thus immediately returning execution to lua, even if the proc being awaited wouldn't sleep. This allows for awaiting extremely expensive non-sleeping procs (like the aforementioned getFlatIcon) * [Lua] You can now `await` expensive non-sleeping procs. Co-authored-by: Y0SH1M4S73R --- code/modules/admin/verbs/lua/helpers.dm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code/modules/admin/verbs/lua/helpers.dm b/code/modules/admin/verbs/lua/helpers.dm index fc53b587d39..c0271e0bc72 100644 --- a/code/modules/admin/verbs/lua/helpers.dm +++ b/code/modules/admin/verbs/lua/helpers.dm @@ -7,6 +7,9 @@ * a proc directly called from auxtools sleeps, the hook returns with whatever * the called proc had as its return value at the moment it slept. This may not * be desired behavior, so this datum exists to wrap these procs. + * + * Some procs that don't sleep could take longer than the execution limit would + * allow for. We can wrap these in a promise as well. */ /datum/auxtools_promise var/datum/callback/callback @@ -20,6 +23,7 @@ /datum/auxtools_promise/proc/perform() set waitfor = 0 + sleep() //In case we have to call a super-expensive non-sleeping proc (like getFlatIcon) try return_value = callback.Invoke() status = PROMISE_RESOLVED