Skip to content

Instantly share code, notes, and snippets.

@y-fedorov
Created April 27, 2016 14:29
Show Gist options
  • Save y-fedorov/b739ad04dcb0974ce1d7223ab349d85c to your computer and use it in GitHub Desktop.
Save y-fedorov/b739ad04dcb0974ce1d7223ab349d85c to your computer and use it in GitHub Desktop.
Javascript Promise example
<!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