title: Asynchronous execution of a function App Script
body: <p>I've been digging around, and I'm not able to find references or documentation on how I can use Asynchronous Functions in Google App Script, I found that people mention It's possible, but not mention how... </p>
  
  <p>Could someone point me in the right direction or provide me with an example? 
  Promises, Callbacks, or something, that can help me with this. </p>
  
  <p>I have this function lets call it <code>foo</code> that takes a while to execute (long enough that It could time out an HTTP call). </p>
  
  <p>What I'm trying to do Is to refactor it, in a way that it works like this:</p>
  
  <pre><code>function doPost(e) {
      // parsing and getting values from e
      var returnable = foo(par1, par2, par3);
        return ContentService
               .createTextOutput(JSON.stringify(returnable))
               .setMimeType(ContentService.MimeType.JSON);
  }
  
  function foo(par1, par2, par3) {
      var returnable = something(par1, par2, par3); // get the value I need to return;
  
      // continue in an Async way, or schedule execution for something else
      // and allow the function to continue its flow
      /* async bar(); */
  
      return returnable;
  }
  </code></pre>
  
  <p>Now I want to realize that bit in <code>foo</code> because It takes to long and I don't want to risk for a time out, also the logic that occurs there it's totally client Independent, so It doesn't matter, I just need the return value, that I'll be getting before. </p>
  
  <p>Also, I think It's worth mentioning that this is deployed in Google Drive as a web app. </p>
  
  <blockquote>
    <p>It's been long since this, but adding some context, at that moment I wanted to scheduled several things to happen on Google Drive, and It was timing out the execution, so I was looking for a way to safely schedule a <em>job</em>.</p>
  </blockquote>