Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let flyToTheMoon = new Promise ((resolve, reject) => {
- const takeOff = startEngine.start(); // our async action
- if (takeOff) {
- resolve("We're sky high") // resolve if successful
- } else {
- reject("We're stuck on earth") // reject if it failed
- }
- });
- // resolve the Promise
- flyToTheMoon.then((asyncResult) => { // then if it was successful
- console.log(asyncResult)
- }).catch((asyncError) => { // catch the error if it fails
- console.log(asyncError)
- });
Add Comment
Please, Sign In to add comment