overte/script-archive/libraries/promiseExample.js

18 lines
441 B
JavaScript
Raw Normal View History

2015-11-06 15:10:23 -08:00
Script.include('promise.js');
var Promise = loadPromise();
var prom = new Promise(function(resolve, reject) {
print('making a promise')
// do a thing, possibly async, then…
var thing = true;
if (thing) {
resolve("Stuff worked!");
} else {
print('ERROR')
reject(new Error("It broke"));
}
});
// Do something when async done
prom.then(function(result) {
print('result ' + result);
});