Created
April 27, 2016 14:29
-
-
Save y-fedorov/b739ad04dcb0974ce1d7223ab349d85c to your computer and use it in GitHub Desktop.
Javascript Promise example
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Test Promise code</title> | |
<script> | |
'use strict'; | |
//Stage 1 | |
var p1 = new Promise(function(resolve, reject) { | |
//Stage 3 Async code here and resolve(value) or regect(value) | |
resolve('done'); | |
}); | |
p1.then(function(val) { | |
//Stage 4 (on resolve) | |
}).catch(function(reason) { | |
//Stage 4 (on reject or error) | |
}); | |
//Stage 2 | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment