Promises and maybe callbacks.
Here’s an example where we fetch a page and count the amount of
As you write more and more code that is asynchronous, you will end up writing
await in front of every expression. That sounds crazy, and it is, but here’s a demo:
> Show transpiled code button below the code to see the transpiled version. As you can see a lot of (unnecessary) awaits got inserted, but at least we don’t have to write them ourselves anymore surely increasing our productivity 10x.
The transpiler is powered by Babel and can be found here.
Why is this a bad idea?#
fetch, but are only willing to wait for two seconds for the result, you’re out of luck.
Secondly, compilers these days are really smart, but user code sprinkling in
await everywhere (including places where it does nothing) likely was not a priority in optimization for the compiler designers.
So what is it good for?#
Use it for fun, use it in experimental code in a notebook (like the above examples), but please don’t put this into production.
Member access expressions are not awaited (as
this would lead to issues when calling a member function). For example:
In practice this likely what you want anyway. If you do need to await member variables you can just write await yourself.
Do edit the code blocks above and play with it :)!