<story><title>JavaScript Promises: There and back again</title><url>http://www.html5rocks.com/en/tutorials/es6/promises/#!</url></story><parent_chain><item><author>jeswin</author><text>Broader adoption of JS on the server will only begin after ES6 generators land in Node. Due to the complexity of async code, writing JS on the server is not easy for the average team.&lt;p&gt;As of now, you could use Promises but it is still kind of messy without generators. Here is a simple example:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  #Without generators
  Credentials.get({ token })
      .then (credentials) =&amp;gt;
          User.get({ username: credentials.username })

  #With generators
  credentials = yield Credentials.get({ token })
  User.get({ username: credentials.username })
&lt;/code&gt;&lt;/pre&gt;
We use FaceBook&amp;#x27;s regenerator project to compile ES6 features down to Node&amp;#x27;s currently supported Javascript features. If you don&amp;#x27;t want to use the --harmony flag, you should really try it out. &lt;a href=&quot;https://github.com/facebook/regenerator&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;facebook&amp;#x2F;regenerator&lt;/a&gt;</text></item></parent_chain><comment><author>zsombor</author><text>Whilst thanks to lack of choice JavaScript is so important on the browser side, I would hope the Node infatuation would eventually pass where you do have a choice. Async calls in Node are done via explicit passing of closures. Callbacks, Promises etc all look bad compared to simple sequential instructions like:&lt;p&gt;&lt;pre&gt;&lt;code&gt;   credentials := NewCredentials(token)
   User.findByName(credentials.userName)   
&lt;/code&gt;&lt;/pre&gt;
The above is in Go, and it is just as fast if not more. Whilst all requests are on their own goroutines, the runtime will schedule them using the same efficient async io that does not need to be made visible as in JavaScript.</text></comment>
<story><title>JavaScript Promises: There and back again</title><url>http://www.html5rocks.com/en/tutorials/es6/promises/#!</url></story><parent_chain><item><author>jeswin</author><text>Broader adoption of JS on the server will only begin after ES6 generators land in Node. Due to the complexity of async code, writing JS on the server is not easy for the average team.&lt;p&gt;As of now, you could use Promises but it is still kind of messy without generators. Here is a simple example:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  #Without generators
  Credentials.get({ token })
      .then (credentials) =&amp;gt;
          User.get({ username: credentials.username })

  #With generators
  credentials = yield Credentials.get({ token })
  User.get({ username: credentials.username })
&lt;/code&gt;&lt;/pre&gt;
We use FaceBook&amp;#x27;s regenerator project to compile ES6 features down to Node&amp;#x27;s currently supported Javascript features. If you don&amp;#x27;t want to use the --harmony flag, you should really try it out. &lt;a href=&quot;https://github.com/facebook/regenerator&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;facebook&amp;#x2F;regenerator&lt;/a&gt;</text></item></parent_chain><comment><author>camus2</author><text>Good but can you yield from the global scope? if not you still need to write at least a function.&lt;p&gt;The hardest stuff in JS is that :&lt;p&gt;&lt;pre&gt;&lt;code&gt;    function F(){throw &amp;quot;error&amp;quot;}

   try{setTimeout(F,1000)}catch(error){ console.log(&amp;quot;error&amp;quot;)}
&lt;/code&gt;&lt;/pre&gt;
we cant catch async errors outside the async callback , will generators fix this ? ( by the way , that&amp;#x27;s why you should never throw any error yourself in js ).</text></comment>