How to run CANVASENGINE server and physics world

Hi.

I'm using the framework canvasengine with node.js. I'm also using box2d framework (physic engine).

The problem is that I have my canvasengine framework running (so it's waiting for connections). I want to run an infinite loop which is stepping the physics world (world.step(fps, iterations)), but it seems that threads aren't existent in node.js. So, how can i accomplish this?

Thanks for your help!

More recent browsers have a function called window.requestAnimationFrame. This function is used to make smooth animations inside the browser. For a safe implementation of the function (you can run it everywhere), take a look at this piece of code:

window.requestAnimationFrame = function() {
    return window.requestAnimationFrame    ||
        window.webkitRequestAnimationFrame ||
        window.mozRequestAnimationFrame    ||
        window.oRequestAnimationFrame      ||
        window.msRequestAnimationFrame     ||
        function(callback) {
            window.setTimeout(callback, 1000 / 60);
        };
};

setInterval(function(){world.step()},1000/60)

should step your world at 60 fps