Skip to content

Instantly share code, notes, and snippets.

@jordwest
Created July 13, 2016 23:48
Show Gist options
  • Save jordwest/b24d0a5e700b86f04177e33a4a9bf026 to your computer and use it in GitHub Desktop.
Save jordwest/b24d0a5e700b86f04177e33a4a9bf026 to your computer and use it in GitHub Desktop.
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