From f2d0f99751a3a7cf36d1091d76db6c6ff01c508c Mon Sep 17 00:00:00 2001 From: Y0SH1M4S73R Date: Thu, 1 Sep 2022 05:20:04 -0400 Subject: [PATCH] [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) --- 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