Created
January 23, 2020 17:55
-
-
Save georgerussellpruitt/96fb94741cec0dd3f2b2f3ded495e67f to your computer and use it in GitHub Desktop.
promise testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head></head> | |
<script type="text/javascript"> | |
console.log("start"); | |
let myFirstPromise = new Promise((resolve, reject) => { | |
// We call resolve(...) when what we were doing asynchronously was successful, and reject(...) when it failed. | |
// In this example, we use setTimeout(...) to simulate async code. | |
// In reality, you will probably be using something like XHR or an HTML5 API. | |
setTimeout( function() { | |
resolve("Success and stuff!") // Yay! Everything went well! | |
}, 250) | |
}) | |
myFirstPromise.then((successMessage) => { | |
// successMessage is whatever we passed in the resolve(...) function above. | |
// It doesn't have to be a string, but if it is only a succeed message, it probably will be. | |
console.log("Yay! " + successMessage) | |
}); | |
console.log("end"); | |
function testing(){ | |
console.log("testing called"); | |
var resp = delayed_response(); | |
resp.then(function(){ | |
console.log(resp); | |
},function(){ | |
console.log("failed resp"); | |
}); | |
console.log(resp); | |
} | |
function callback_test(str){ | |
console.log(str); | |
} | |
function promise_test(){ | |
console.log("promise_test called"); | |
} | |
function delayed_response(resp){ | |
console.log("delayed_response called"); | |
setTimeout(function(){ | |
console.log("after timer"); | |
resp = "dumb value"; | |
return resp; | |
},1000); | |
} | |
</script> | |
<body></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment