Created
July 15, 2015 04:26
-
-
Save kreegr/c8533da1f277a0cd1c67 to your computer and use it in GitHub Desktop.
Cycling Ajax Requests
This file contains hidden or 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>Document</title> | |
</head> | |
<body> | |
<script src="bower_components/jquery/dist/jquery.min.js"></script> | |
<script src="bower_components/bluebird/js/browser/bluebird.min.js"></script> | |
<script src="bower_components/lodash/lodash.min.js"></script> | |
<script> | |
var genUrlPromise = function genUrlPromise(url){ | |
var p = Promise.resolve($.get(url)); | |
p.finally(function(){ | |
promiseMap[url] = genUrlPromise(url); | |
}); | |
return p; | |
}; | |
var promiseMap = _.chain(16) | |
.times(_.partial(_.random, 1, 200, false)) | |
.reduce(function(promiseMap, r){ | |
var url = 'http://localhost:3000/test/' + r; | |
promiseMap[url] = genUrlPromise(url); | |
return promiseMap; | |
}, {}) | |
.tap(function(pMap){ | |
console.log(pMap); | |
}) | |
.value(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment