overte/examples/libraries/promiseExample.js
James B. Pollack ced1a4899d promises
2015-11-06 15:10:23 -08:00

18 lines
No EOL
441 B
JavaScript

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);
});