What promise code example
Example 1: .promise()
var promise = new Promise(function(resolve, reject) {
// do some long running async thing…
if (/* everything turned out fine */) {
resolve("Stuff worked!");
}
else {
reject(Error("It broke"));
}
});
Example 2: promise js
A promise is an object that may produce a single value some time in the future:
either a resolved value, or a reason that it’s not resolved