SHARE
TWEET

Untitled

a guest Jul 16th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let myFirstPromise = new Promise((resolve, reject) => {
  2.   /* do something asynchronous
  3.      which eventually calls either:
  4.      resolve(someValue); // fulfilled
  5.      or
  6.      reject("failure reason"); // rejected
  7.   */
  8.  
  9.   setTimeout(function(){
  10.     resolve("success!"); // Yay! Everything went well!
  11.   }, 250);
  12. });
  13.  
  14. myFirstPromise.then((successMessage) => {
  15.   /* successMessage is whatever we passed
  16.    in the resolve(...) function above.
  17.    It can be any type of object. */
  18.   console.log("Yay! " + successMessage);
  19.  
  20. }).catch((error) => {
  21.   /* error is whatever we passed
  22.    in the reject(...) function. */
  23.   console.log(error);
  24. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top