Last active
November 7, 2015 00:14
-
-
Save dmh2000/ddff17a3d53ba93ad68c to your computer and use it in GitHub Desktop.
browser promise chain
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> | |
<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