TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Taming the asynchronous beast with ES7

30 pointsby nolanlabout 10 years ago

8 comments

daleharveyabout 10 years ago
I promised Nolan a response on why I didnt particularly agree with this post when I merged it, figure may as well here.<p>I think all the caveats applied to async function (ensure its inside a try&#x2F;catch, dont use for in) points to how complicated it can be, <a href="http://jakearchibald.com/2014/es7-async-functions/" rel="nofollow">http:&#x2F;&#x2F;jakearchibald.com&#x2F;2014&#x2F;es7-async-functions&#x2F;</a> had to be amended with notes because a bunch of people very familiar with this style of coding still get it wrong. I cant see myself explaining to a new programmer how this all works.<p>I would really like to see us return to nice obvious blocking functions, taking the example the simplest way of all seems to be ...<p><pre><code> let db = new PouchDB(&#x27;mydb&#x27;); let result = db.post({}); let doc = db.get(result.id); console.log(doc); </code></pre> Let workers (or whatever equivalent they come up with in node) to make sure we dont block a single event loop and live happily ever after.<p>Basically copy erlang, but without actually having to use erlang.
评论 #9178525 未加载
评论 #9179748 未加载
评论 #9181426 未加载
评论 #9179179 未加载
hacknatabout 10 years ago
I like that we&#x27;re all starting to wake up from this callback nightmare in pretty much every language. It&#x27;s funny to me that it took us going through a full blown callback orgy for us to realize that all we wanted to begin with was an abstraction of spawning threads and doing non-blocking i&#x2F;o (makes sense, having to reason about locking is, often, unnecessary). I realize callbacks&#x2F;lambdas have their place, but it was really starting to chaff.
Dirlewangerabout 10 years ago
Cool and concise article.<p>This is just me thinking out loud, but the look-ahead...will it ever end? You say ES7 is bleeding edge, but that&#x27;s contingent on the context. In terms of browser support&#x2F;widespread adoption right now, ES6 is bleeding edge. How many years...<i>decades</i> is something like ES7 away from ever being implemented in the majority of browsers out there? How much more will the web development landscape have even changed by then?
评论 #9178443 未加载
BFayabout 10 years ago
Does this offer any benefits over building coroutine functions with generators? The &quot;co&quot; library (and probably some others) do this.<p><a href="https://github.com/tj/co" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tj&#x2F;co</a><p>It seems mostly like a syntactical difference to me - with coroutines you &quot;yield&quot; instead of &quot;await.&quot; You can still wrap things nicely in try{} catch{} blocks.<p>But the readme for co does mention that it&#x27;s a stepping stone towards async&#x2F;await. I like that ES7 will allow us to write this style of function without including an additional library, but apart from that, is there a big gap in functionality between the different approaches?
the8472about 10 years ago
&gt; However, promisey code is still hard to read, because promises are basically a bolt-on replacement for language primitives like try, catch, and return<p>I find promises quite readable when combined with arrow functions. async&#x2F;await certainly is nice, but the difference in readability doesn&#x27;t seem that big to me.
评论 #9179375 未加载
评论 #9178998 未加载
streptomycinabout 10 years ago
Seems like there are a lot of edge cases described in this article that could be confusing when using async&#x2F;await. Is anyone else feeling ambivalent that async&#x2F;await is actually a nicer syntax than just using promises?
highpixelsabout 10 years ago
await* is awesome too:<p><pre><code> let arr = [&#x2F;* an array of promises *] await* arr; </code></pre> Essentially the same as Promise.all<p><pre><code> let arr = [&#x2F;* an array of promises *] await Promise.all(arr)</code></pre>
thesorrowabout 10 years ago
I&#x27;m using channels (with the awesome js-csp lib) for managing server-side asynchronous code and so far it&#x27;s really good. As a bonus I can use transducers with generators :)