Created
July 13, 2016 23:48
-
-
Save jordwest/b24d0a5e700b86f04177e33a4a9bf026 to your computer and use it in GitHub Desktop.
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
import * as https from 'https'; | |
async function fetchHeaders( url: string ) { | |
return new Promise( ( resolve, reject ) => { | |
https.get( url, response => { | |
resolve( response.headers ); | |
} ); | |
} ); | |
} | |
async function test() { | |
// Runs one-by-one | |
var wpcomHeaders = await fetchHeaders( 'https://wordpress.com' ); | |
console.log( wpcomHeaders ); | |
var googleHeaders = await fetchHeaders( 'https://google.com/' ); | |
console.log( googleHeaders ); | |
// Runs in parallel | |
var headers = await Promise.all( [ | |
fetchHeaders( 'https://wordpress.com' ), | |
fetchHeaders( 'https://google.com/' ), | |
] ); | |
console.log( headers ); | |
} | |
test(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment