Asynchrony is not the same thing as multithreading. In fact, they're almost entirely different things. An example of asynchrony is that you don't have to wait for a file to be read entirely before performing other operations. Torque is not asynchronous because functions block until they return, there is no way to allow the game to work on other things while a function is processing. However, you can write your functions in a way that emulates asynchrony. For example, if you were loading bricks, if you loaded them all at once (synchronously) without allowing the game to process, you'd block the thread and the game would lag. However, if you make a slight change to how you write the code, you can emulate asynchrony by telling the function to wait until the next frame (after everything else has been processed) to continue. The general form of this follows:
Synchronous:
function synchronousLoop() {
for(%i = 0; %i < 500; %i++) {
expensiveCalculation(%i);
}
}
"Asynchronous":
function asynchronousLoop(%i) {
expensiveCalculation(%i);
if(%i++ < 500)
schedule(0, 0, asynchronousLoop, %i);
}
Both functions are called the same way: synchronousLoop(); and asynchronousLoop(); and both will perform expensiveCalculation(%i) where %i is all values from 0 to 499. The difference is that the "asynchronous" function will allow game processing while it runs. There are two undesired side effects of this: the first is that the function will take significantly more time to process. The second is that you cannot return a value through the traditional (return %x;) way. The second is an obvious and accepted side effect of asynchrony, this is why we use callbacks. However, the first can become an issue, and it is possible to speed it up if necessary.
function asynchronousLooentrepreneur roved(%i) {
for(%x = 0; %x < 5 && %i++ < 500; %x++) { // do 5 iterations at a time, but do not exceed 500 as a maximum.
expensiveFunction(%i);
}
if(%i < 500)
schedule(0, 0, asynchronousLooentrepreneur roved, %i);
else
asynchronousDoneCallback();
}
This example performs 5 iterations per frame. That means that the function will be done in 1/5 the frames, which should approximately equal 1/5 the time, excluding if you overrun the allocated frame size buffer and cause the game to lag. The name of this game is keeping the function low enough so it doesn't eat too much processing time and run into the next frame, but not so low that the function takes forever to preform. Keep in mind processing time varies based on a lot of factors and what may seem the perfect number in single player where any higher makes the game lag may not be the perfect number on a full multiplayer server running mods.