From b19c1682ea8731c11a9af7972de3ad2a9aa9102e Mon Sep 17 00:00:00 2001 From: Bruce McPherson Date: Tue, 24 May 2016 15:08:23 +0100 Subject: [PATCH] updated by GasGit automation --- scripts/Provoke.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 scripts/Provoke.js diff --git a/scripts/Provoke.js b/scripts/Provoke.js new file mode 100644 index 0000000..12f9151 --- /dev/null +++ b/scripts/Provoke.js @@ -0,0 +1,49 @@ +/** + * @namespace Provoke + * promise management for async calls + */ + +var Provoke =(function (ns) { + + /** + * run something asynchronously + * @param {string} namespace the namespace (null for global) + * @param {string} method the method or function to call + * @param {[...]} the args + * @return {Promise} a promise + */ + ns.run = function (namespace,method) { + + // the args to the server function + var runArgs = Array.prototype.slice.call(arguments).slice(2); + + if (arguments.length<2) { + throw new Error ('need at least a namespace and method'); + } + + // this will return a promise + return new Promise(function ( resolve , reject ) { + + google.script.run + + .withFailureHandler (function(err) { + reject (err); + }) + + .withSuccessHandler (function(result) { + resolve (result); + }) + + .exposeRun (namespace,method,runArgs); + }); + + + }; + + + return ns; + +})(Provoke || {}); + + +