title: ES2017 - Async vs. Yield
body: <p>I am confused about the current discussion of adding async functions and the keyword <code>await</code> to the next EcmaScript.</p>
  
  <p>I do not understand why it is necessary to have the <code>async</code> keyword before the <code>function</code> keyword.</p>
  
  <p>From my point of view the <code>await</code> keyword to wait for a result of a generator or promise <em>done</em>, a function's <code>return</code> should be enough.</p>
  
  <p><code>await</code> should simple be usable within normal functions and generator functions with no additional <code>async</code> marker.</p>
  
  <p>And if I need to create a function what should be usable as an result for an <code>await</code>, I simply use a promise.</p>
  
  <p>My reason for asking is <a href="http://kaye.us/javascript-async-control-flow/" rel="noreferrer">this</a> good explanation, where the following example comes from:</p>
  
  <pre><code>async function setupNewUser(name) {  
    var invitations,
        newUser = await createUser(name),
        friends = await getFacebookFriends(name);
  
    if (friends) {
      invitations = await inviteFacebookFriends(friends);
    }
  
    // some more logic
  }
  </code></pre>
  
  <p>It also could be done as normal function, if the execution of a function will wait for finishing the hole function until all awaits are fulfilled.</p>
  
  <pre><code>function setupNewUser(name) {  
    var invitations,
        newUser = await createUser(name),
        friends = await getFacebookFriends(name);
  
    if (friends) {
      invitations = await inviteFacebookFriends(friends);
    }
  
    // return because createUser() and getFacebookFriends() and maybe inviteFacebookFriends() finished their awaited result.
  
  }
  </code></pre>
  
  <p>In my opinion the whole function execution is holding until the next tick (await fulfillment) is done.  The difference to Generator-Function is that the next() is triggering and changing the object's value and done field. A function instead will simple give back the result when it is done and the trigger is a function internal trigger like a while-loop.</p>