To make a promise, create and return it:
promise = new Promise(function (resolve, reject) {
// do what you would have done if you hadn't made the promise
// if it works out, call resolve() with whatever you would have returned as its argument
// otherwise, call reject() with an Error() specifying a reasing for failure
});
To use a promise, call then():
promise.then(
function (value) { /* it worked! do something with the value */ },
function (reason) { /* problems: fail based on the error provided */ }
);