setTimeout and V8

For what it's worth, V8 has its own setTimeout now (~7.5 years later), in the shell it provides. But it only takes one parameter (the function to call) and schedules it to be called once the current job is completed, roughly as though you'd passed 0 as the second parameter to the more familiar form of setTiemout provided by browsers and Node.js.

So given example.js:

console.log("a");
setTimeout(() => {
    console.log("c");
}, 5000);
console.log("b");

then

$ v8 example.js

outputs

a
b
c

...with no appreciable delay between b and c.

(That example uses the v8 command installed by jsvu, which is at least one way you run code directly in V8. I think d8 got subsumed...)


setTimeout is not part of ECMA-262, it's implemented by the browsers. However, if you install Node.js (which is V8 + extras) you will get a command line setTimeout.

Tags:

Javascript

V8