diff --git a/code/__DEFINES/callbacks.dm b/code/__DEFINES/callbacks.dm index 705b8066119..8808c045abb 100644 --- a/code/__DEFINES/callbacks.dm +++ b/code/__DEFINES/callbacks.dm @@ -1,6 +1,23 @@ #define GLOBAL_PROC "some_magic_bullshit" /// A shorthand for the callback datum, [documented here](datum/callback.html) #define CALLBACK new /datum/callback -#define INVOKE_ASYNC world.ImmediateInvokeAsync + +///Per the DM reference, spawn(-1) will execute the spawned code immediately until a block is met. +#define MAKE_SPAWN_ACT_LIKE_WAITFOR -1 +///Create a codeblock that will not block the callstack if a block is met. +#define ASYNC spawn(MAKE_SPAWN_ACT_LIKE_WAITFOR) + +#define INVOKE_ASYNC(proc_owner, proc_path, proc_arguments...) \ + if ((proc_owner) == GLOBAL_PROC) { \ + ASYNC { \ + call(proc_path)(##proc_arguments); \ + }; \ + } \ + else { \ + ASYNC { \ + call(proc_owner, proc_path)(##proc_arguments); \ + }; \ + } + /// like CALLBACK but specifically for verb callbacks #define VERB_CALLBACK new /datum/callback/verb_callback diff --git a/code/datums/callback.dm b/code/datums/callback.dm index 30cca6fd49c..a51639d0b9b 100644 --- a/code/datums/callback.dm +++ b/code/datums/callback.dm @@ -67,26 +67,6 @@ arguments = args.Copy(3) if(usr) user = WEAKREF(usr) -/** - * Immediately Invoke proctocall on thingtocall, with waitfor set to false - * - * Arguments: - * * thingtocall Object to call on - * * proctocall Proc to call on that object - * * ... optional list of arguments to pass as arguments to the proc being called - */ -/world/proc/ImmediateInvokeAsync(thingtocall, proctocall, ...) - set waitfor = FALSE - - if (!thingtocall) - return - - var/list/calling_arguments = length(args) > 2 ? args.Copy(3) : null - - if (thingtocall == GLOBAL_PROC) - call(proctocall)(arglist(calling_arguments)) - else - call(thingtocall, proctocall)(arglist(calling_arguments)) /** * Invoke this callback diff --git a/code/datums/components/construction.dm b/code/datums/components/construction.dm index df1f90c21b2..48cb0fb1103 100644 --- a/code/datums/components/construction.dm +++ b/code/datums/components/construction.dm @@ -33,8 +33,9 @@ /datum/component/construction/proc/action(datum/source, obj/item/I, mob/living/user) SIGNAL_HANDLER - - return INVOKE_ASYNC(src, PROC_REF(check_step), I, user) + ASYNC //This proc will never actually sleep, it calls do_after with a time of 0. + . = check_step(I, user) + return . /datum/component/construction/proc/update_index(diff) index += diff diff --git a/code/datums/components/payment.dm b/code/datums/components/payment.dm index b4e5f596b27..81c93af6853 100644 --- a/code/datums/components/payment.dm +++ b/code/datums/components/payment.dm @@ -121,7 +121,10 @@ holochange.name = "[holochange.credits] credit holochip" if(ishuman(user)) var/mob/living/carbon/human/paying_customer = user - if(!INVOKE_ASYNC(paying_customer, TYPE_PROC_REF(/mob, put_in_hands), holochange)) + var/successfully_put_in_hands + ASYNC //Put_in_hands can sleep, we don't want that to block this proc. + successfully_put_in_hands = paying_customer.put_in_hands(holochange) + if(!successfully_put_in_hands) user.pulling = holochange else user.pulling = holochange diff --git a/code/modules/vehicles/mecha/mecha_construction_paths.dm b/code/modules/vehicles/mecha/mecha_construction_paths.dm index d3d8702f601..7df97650d0e 100644 --- a/code/modules/vehicles/mecha/mecha_construction_paths.dm +++ b/code/modules/vehicles/mecha/mecha_construction_paths.dm @@ -384,7 +384,9 @@ outer_plating_amount=1 /datum/component/construction/mecha/gygax/action(datum/source, atom/used_atom, mob/user) - return INVOKE_ASYNC(src, PROC_REF(check_step), used_atom,user) + ASYNC //This proc will never actually sleep, it calls do_after with a time of 0. + . = check_step(used_atom, user) + return . //CLARKE /datum/component/construction/unordered/mecha_chassis/clarke