Last active
August 29, 2015 14:01
-
-
Save yf-hk/c0b3e2c262ad3a17ec3b to your computer and use it in GitHub Desktop.
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
var Promise = require('bluebird'); | |
var request = Promise.promisifyAll(require('request')); | |
ENABLE_FIDDLER_PROXY = false; | |
var proxy = ENABLE_FIDDLER_PROXY ? {proxy: 'http://127.0.0.1:8888'} : {}; | |
console.log('before all requests'); | |
// Google and v2ex are parallel requests | |
// It loads baidu only after google is finished | |
// When they are all finished, it goes to the final spread function | |
Promise.all([ | |
request.getAsync('http://www.google.com.hk', proxy) | |
.then(function(google) { | |
console.log('google done, loading baidu') | |
return request.getAsync('http://www.baidu.com', proxy) | |
}), | |
request.getAsync('http://v2ex.com', proxy)]) | |
.spread(function(baidu, v2ex) { | |
console.log('all done'); | |
}); | |
console.log('google & v2ex started'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment