Script Handle
A Script Handle, used to identify scripts in script operations called using spawn or execVM. Introduced with ArmA: Armed Assault, does not refer to Operation Flashpoint or Operation Flashpoint: Resistance.
This handle's status can be checked with scriptDone, it can be terminated with terminate.
Promise Handles
Since 2.22 Script handles can be used as promises.
A Promise is either a Script Handle to a spawn'ed or execVM'ed script, or an "Empty Handle" that does not hold a backing script. The Handle can be used to wait for the a result to be available. In case of a "real" handle that means the scheduled script returning a value, or in the case of a "Empty Handle" by using terminate to set a result value.
A Promise can have continuations added onto it with continueWith, which is script code that will execute once the handle is completed.
Handles can be used with waitUntil, continueWith, terminate, scriptDone, name
Creating a Promise
Every handle returned by spawn or execVM is a promise that gets resolved once the script exits.
It's also possible to create a "Empty Handle" which does not hold any scheduled script, and can also be used in unscheduled code.
A "Empty Handle" needs to be "completed" by calling terminate on it.
Using Promises
Promises can be used to simplify asynchronous operations. For example, when calling a function that takes some time to complete, and then wanting to execute code after it has completed.
To show it on an example, let's say we have a function that paradrops a vehicle. And we want to wait for the vehicle to touch the ground and then spawn a smoke grenade on it.
Previously, that could be solved like so:
Also note how the waitUntil always runs. Even if we as the caller do not care for the paradrop to finish, we wouldn't easily have the option to tell the script that, without adding another parameter to it. Also note that this function is not usable in unscheduled scripts, because it uses waitUntil to wait for the landing.
With promises, it can be solved like this:
Note that the paradrop function can now also be used in scheduled scripts like so:
Or like so: