Files
Bubberstation/code/datums/callback.dm
Kapu1178 4ab46358c0 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>
2023-03-04 19:33:37 -08:00

6.7 KiB