SHARE
TWEET

Untitled

a guest Jun 19th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const order = true;
  2. const food = "Hamburger";
  3.  
  4. let newOrder = new Promise((resolve, reject) => {
  5.   setTimeout(() => {
  6.     if (order) {
  7.       resolve(`Your ${food} is ready to pick up!`);
  8.     } else {
  9.       reject(Error(`Sorry, we ran out of ${food}`));
  10.     }
  11.   }, 3000);
  12. });
  13.  
  14. newOrder
  15.   .then(value => {
  16.     console.log(value); // The order is set to true so the promise is resolved after 3 seconds.
  17.   //Your Hamburger is ready to pick up!
  18.   })
  19.   .catch(err => console.log(err)); // if the variable order were set to false it will have catched the error.
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