Interestingly, V8 now has its own version of the setTimeout
function, implemented approximately 7.5 years after its initial introduction. This function, available in the shell it provides, only requires one parameter (the function to call) and schedules it to be executed once the current task is finished. It behaves similarly to passing 0
as the second parameter in the traditional form of setTimeout
found in browsers and Node.js.
For instance, if we have a file named example.js
containing:
console.log("a");
setTimeout(() => {
console.log("c");
}, 5000);
console.log("b");
When running the following command:
b
and c
.
(This demonstration uses the v8
command from jsvu, which offers a way to execute code directly within V8. The former command d8
may no longer be in use...)