Promise basics

let promise = new Promise(function(resolve, reject) { // the function is executed automatically when the promise is constructed // after 1 second signal that the job is done with the result "done" setTimeout(() => resolve("done"), 1000); });
promise.then( function(result) { /* handle a successful result */ }, function(error) { /* handle a reject */ } );