Files
Bubberstation/code/datums/callback.dm
SkyratBot c41ff0aaa6 [MIRROR] Optimizes INVOKE_ASYNC by making it a macro and avoiding a proc call [MDB IGNORE] (#19668)
* Optimizes INVOKE_ASYNC by making it a macro and avoiding a proc call (#73264)

## About The Pull Request
This is quite literally the same behavior but faster, and also catches
improper arguments better than the old macro/proc approach.

Credit to Lohikar for writing the macro.
Port of https://github.com/DaedalusDock/daedalusdock/pull/196

Also, `world.ImmediateInvokeAsync()` never set a return value, so
expecting one was never valid behavior.

At MSO's request, the documentation of `spawn(-1)`:

As per the reference, calling `spawn()` with a negative value will
execute the spawned code until a blocking action (such as `sleep()`) is
encountered. Then, it will step outside of the spawned code, and
continue the proc. This is the same behavior as calling a `waitfor =
FALSE` proc. Specifically, under the hood, `spawn(-1)` creates a copy of
the callstack like `sleep()`, incase the spawned code is blocked and
needs to be rescheduled.

As an added bonus, `spawn(-1)` silences SHOULD_NOT_SLEEP errors, whereas
`waitfor = FALSE` does not.

## Why It's Good For The Game

ITS FREE FUCKING CPU TIME

---------

Co-authored-by: Mothblocks <35135081+Mothblocks@ users.noreply.github.com>
Co-authored-by: Kyle Spier-Swenson <kyleshome@ gmail.com>

* Optimizes INVOKE_ASYNC by making it a macro and avoiding a proc call

---------

Co-authored-by: Kapu1178 <75460809+Kapu1178@users.noreply.github.com>
Co-authored-by: Mothblocks <35135081+Mothblocks@ users.noreply.github.com>
Co-authored-by: Kyle Spier-Swenson <kyleshome@ gmail.com>
2023-03-04 19:55:24 -08:00

6.7 KiB