Does async/await solve a real problem?

Florian Bösch pyalot at gmail.com
Thu Sep 11 23:24:48 PDT 2014


On Fri, Sep 12, 2014 at 8:00 AM, Tom Van Cutsem <tomvc.be at gmail.com> wrote:
>
> While this refactoring may be tedious (no disagreement there), it forces
> you to review all affected code, which is good, because the dependencies of
> that code may have changed (i.e. side-effect the client previously thought
> would execute atomically may now no longer be atomic).
>

It's often the case that the code which uses the async code, uses other
code, which isn't authored by the author, and isn't documented for await
compatibility. For instance:

$.each(somelist, async function(item){
    await Foobar(item);
});

Suppose $ is jQuery, is this async safe? Google for jQuery documentation
and/or read code.

somelist.each(async function(item){
  await Foobar(item);
});

Has the browser made his each function async safe? Google for JS API
documentation of the browser and/or start reading the source code of the
browser (really?).

This is kind of a pervasive problem. It's not only that the
refactoring/hunting for references is tedious. It's that sometimes, you
might not have the plain source (some proprietary/minified/obfuscated
library anybody?), or that the implementation is quite complex, and
frankly, you just don't have the time to hunt around its millions of lines
of code to figure out if it'll work.

Now to be fair, the same problem applies to co-routines as well. You can't
know if a given piece of code is co-routine safe unless you dig it up. But
at least it doesn't make you type forwards/backwards await/async each time
you decide it didn't work out, trough hundreds, or thousands, or maybe even
tens of thousands of lines. In fact, doing this will become an utter
impossibility fairly quickly anyway, and the only way to do it would be
some kind of automated tool that can insert the async/awaits for you trough
the code (pray that it's inferrable, or you're screwed). Ohyeah, it'd be
nice if that tool could insert some invisible code so you don't just
clutter lines with stuff you don't hand-manage anyway. Wait, no, that was
co-routines again wasn't it? silly me.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140912/24a3cf72/attachment.html>


More information about the es-discuss mailing list