Skip to content

Instantly share code, notes, and snippets.

@dmh2000
Last active November 7, 2015 00:14
Show Gist options
  • Save dmh2000/ddff17a3d53ba93ad68c to your computer and use it in GitHub Desktop.
Save dmh2000/ddff17a3d53ba93ad68c to your computer and use it in GitHub Desktop.
browser promise chain
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<script>
$.get("http://cdn.jsdelivr.net/ramda/0.18.0/ramda.min.js",
function(data,status,jqxhr) {
console.log(R);
},
"script"
);
var work = function(value) {
console.log('work ' + value);
return new Promise(function(resolve,reject) {
console.log('promise ' + value);
setTimeout(function() {
console.log('resolve ' + value);
resolve(value+1);
},1000);
});
}
var p = new Promise(function(resolve,reject) {
console.log('new promise 1');
setTimeout(function() {
console.log('resolve 1');
resolve(2);
},1000);
})
.then(work)
.then(work)
.then(work)
.then(work)
.then(function(value) {
console.log('then 3 ' + value);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment