Async/await are really handy, but I want the opposite of their behavior. Instead of other functions continuing on unless I manually ask them to await a promise, I want functions to yield unless I manually specify that they continue running in parallel.
For instance, this code would print out 1 3 2
:
function wait(ms) {
return new Promise(r => setTimeout(r, ms));
}
async function a() {
console.log("1");
await wait(5000);
console.log("2");
}
a();
console.log("3");
I want it to print out 1 2 3
, with function a()
not actually returning until I've waited 5 seconds and 2 has been printed. I'm making an extension that I'd prefer to be lightweight, so I'd rather not use 3rd party libraries.
Is there any way to do this?
a()
not actually returning until I've waited 5 seconds" That's simply not possible, unless Chrome exposes such a functionality to plugins. – Annabelannabela