Skip to content

Comment on Async/await support in Firefox

Comments

Dear Javascript coders:

If you wind up writing the word "await" in your codebase more than once, you're doing it wrong. You will quickly see how futures/promises wind up taking over all of your code. This is a very good thing. You shouldn't need to block, ever.

Sincerely,

Scala coders

Am I missing something? Await doesn't block. It's just syntactic sugar for Promise.then(() => {}) without having to go down into callback hell.

It makes code more readable and easier to write, but doesn't fundamentally change how it is working under the hood, as far as I am aware.

  var txt = await read();
  // This code is blocked until read() completes.
  console.log(txt);

It is in essence:

    read((err, txt) => {
        console.log(txt)
    })
Or
     read().then((txt) => console.log(txt))
Why is it bad?

Await doesn't synchronously block in Javascript.

http://docs.scala-lang.org/overviews/core/futures.html#block...

And how do you suggest to do that without "blocking"? :) Sure, you could use a stream but that isn't always possible or practical.

That's not what blocking means.

Well, it depends...

async function is blocked on await statement, after all that's why it has such a name.

It does not block the whole VM but task (async function) is effectively blocked for an observer inside it.

Yes but when you talking about async/await, "blocking" means "blocking the thread". And this is very clearly what mehwoot meant.

Care to elaborate a bit? Just trying to understand why async/await is bad. In my mind it makes for much cleaner code that the callback hell.

Also, how is Scala doing it?

Scala is doing it exactly as in JS. We have async/await as a macro library transforming the code to a FSM. The original author posting this probably didn't know that, under-the-hood, await doesn't really block in Scala nor in JS.

Dear Scala coders,

Why have you decided to rewrite everything?

Sincerely, Everyone else. (Obviously not JavaScript coders, sadly...)

P.s. I can only hope you have a somewhat sane release story now.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.