Here is one way to do it. Make sure that all variables that you should always be scope are declared in an external function. Due to the rules of the Javascript scope, they will be available in every subfunction.
function paused() {
var var1, var2, var3;
function part1() {
}
function part2() {
}
setTimeout(part1, 0);
setTimeout(part2, 100);
}
Assuming there are many parts, timeouts can even be entered into a loop:
function paused() {
var var1, var2, var3;
var parts = [
function() {
},
function() {
},
function() {
}
];
for (var i = 0; i < parts.length; i++) {
setTimeout(parts[i], i * 100);
}
}
Be sure to be careful in use this, as internal functions will double-check it.
Note that the global function always executes the suspended parts in order, regardless of whether each individual part will be occupied for more than 100 ms, due to how the Javascript event queue works. When the event queue sees that several setTimeouts can be executed at the same time, priority must be in the queue.