Guest User

Untitled

a guest
Nov 20th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. let flyToTheMoon = new Promise ((resolve, reject) => {
  2. const takeOff = startEngine.start(); // our async action
  3. if (takeOff) {
  4. resolve("We're sky high") // resolve if successful
  5. } else {
  6. reject("We're stuck on earth") // reject if it failed
  7. }
  8. });
  9.  
  10. // resolve the Promise
  11. flyToTheMoon.then((asyncResult) => { // then if it was successful
  12. console.log(asyncResult)
  13. }).catch((asyncError) => { // catch the error if it fails
  14. console.log(asyncError)
  15. });
Add Comment
Please, Sign In to add comment