3 ms·
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
by mehwoot 10y ago
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.
- mark242 10y agovar txt = await read(); // This code is blocked until read() completes. console.log(txt);
- kinkdr 10y agoIt is in essence: read((err, txt) => { console.log(txt) }) Or read().then((txt) => console.log(txt)) Why is it bad?
- olalonde 10y agoAnd how do you suggest to do that without "blocking"? :) Sure, you could use a stream but that isn't always possible or practical.
- solipsism 10y agoThat's not what blocking means.
- c-smile 10y agoWell, 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.
- solipsism 10y agoYes but when you talking about async/await, "blocking" means "blocking the thread". And this is very clearly what mehwoot meant.
- danneu 10y agoAwait doesn't synchronously block in Javascript. http://docs.scala-lang.org/overviews/core/futures.html#blocking-outside-the-future http://docs.scala-lang.org/overviews/core/futures.html#block...
- idobai 10y ago> Am I missing something? Await doesn't block. Then that is NOT the await mechanism...