TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Faking Co-Routines, or Why Callback Hell Is Over (2014)

35 点作者 dyoder大约 9 年前

8 条评论

erikpukinskis大约 9 年前
I have yet to see an &quot;improvement&quot; on callbacks, whether it&#x27;s promises or fibers or generators, where the benefit in readability is worth the havoc it wreaks on my ability to debug the program.<p>These days I write JavaScript using only functions, literals, variables, and the occasional prototype and it&#x27;s amazing.<p>I think many programmers have a desire to believe they are working on complex problems that demand sophisticated tools. I remember learning Ruby and being excited whenever I found a reason to write a DSL. In retrospect it was unnecessary every time. In every case the code would&#x27;ve been clearer if I had just stuck with functions and kept refactoring until I had the right interfaces and data structures.<p>It helps to remember<p><pre><code> function a() { b(function() { &#x2F;&#x2F;etc }) } </code></pre> is equivalent to<p><pre><code> function a() { b(c) } function c() { &#x2F;&#x2F;etc } </code></pre> which is not particularly more verbose. And as a side benefit, refactoring that way gives you an opportunity to make c() self-documenting.
评论 #11340806 未加载
评论 #11340842 未加载
评论 #11342568 未加载
outside1234大约 9 年前
Please: Do not use CoffeeScript in your examples.<p>It is not common to have &quot;readability&quot; in CoffeeScript and it restricts a significant number of readers from being able to understand the code sample.
评论 #11341991 未加载
Azkar大约 9 年前
I don&#x27;t understand why he talks about a javascript problem being solved, then goes on to show us examples in coffee script.
评论 #11340884 未加载
评论 #11341072 未加载
pspeter3大约 9 年前
I still don&#x27;t get why async&#x2F;await is inherently better than using Promises&#x2F;Streams. Is it purely a syntax difference or is there a semantic difference as well?
评论 #11340828 未加载
scriby大约 9 年前
<a href="https:&#x2F;&#x2F;github.com&#x2F;scriby&#x2F;asyncblock-generators" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;scriby&#x2F;asyncblock-generators</a><p>That&#x27;s a control flow solution I wrote on top of generators to make it a little easier to manage parallel tasks, timeouts, error handling, and so on.<p>I originally made asyncblock, which was based on fibers a few years ago. This module uses the same underpinnings as asyncblock, just based in generators instead of fibers.
amelius大约 9 年前
The problem with javascript coroutines is that you can only yield from within the generator itself, not from a called function.<p>This makes it impossible, for instance, to write a nice I&#x2F;O library that is to be called from within a generator (the library is supposed to yield on a blocking situation).
teddyh大约 9 年前
What’s with the HUGE FONT SIZE?
raspasov大约 9 年前
Use ClojureScript + core.async and get some work done.
评论 #11343423 未加载