VideosMy ProjectsProgramming BlogGallery
  1. Home
  2. Blog
  3. Use promises in Google Apps Scripts
Programming Blog

Atom/RSS Feed

google/google_apps_script

Use promises in Google Apps Scripts

google/google_apps_script

To use the latest es6 Promises in google app scripts it is very trivial to do so.

You need to include the Promises in the polyfill

Including Promises

Include the following code at the top of your file which you wish to use promises in.

var Promise,
   setTimeout = setTimeout || function (func,ms) {
     Utilities.sleep(ms);
     func();
   };

(function () {  

 // get the polyfill and eval
 if (!Promise) {
   var result = UrlFetchApp.fetch('https://cdnjs.cloudflare.com/ajax/libs/es6-promise/3.2.1/es6-promise.min.js');
   eval (result.getContentText());

   // add done for compatibility with other promise systems
   Promise.prototype.done = Promise.prototype.done || Promise.prototype.then ;

 }

}());
Join my mailing list