by lioeters · 5y ago · 0 comments
It's a transpiler that puts "await" in front of every expression, resulting in code like:
(async () => {
async function fetchPageBody(url) {
return await (await (await fetch)(await url)).text();
}
async function sleep(ms) {
return await new (await Promise)(await (async (resolve) => await (await setTimeout)(await (async () => await (await resolve)()), await ms)));
}
const body = await (await fetchPageBody)("https://enable-cors.org/");
const numDivs = (await ((await (await body).match(/<div/g)) || (await []))).length;
await (await console).log("Number of divs:", await numDivs);
await (await sleep)(2000);
await (await console).log("This prints after two seconds.");
})();As far as I can tell, the only real problem is performance. Wrapping synchronous expressions in Promise.resolve() (which is what this effectively does) is apparently not optimized out by V8, and is egregiously inefficient: https://madelinemiller.dev/blog/javascript-promise-overhead/
For my use-case, probably what I'll end up doing is having the compiler be smart and only invisibly insert those asyncs/awaits where it actually needs to