Skip to content

Instantly share code, notes, and snippets.

@arvi
Last active Aug 10, 2018
Embed
What would you like to do?
function hello() {
return new Promise(function(resolve, reject) {
resolve('hello')
});
}
function helloThere() {
return 'helloThere';
}
async function beers() {
const beersList = await fetch('https://api.punkapi.com/v2/beers/1');
return beersList.text();
}
var promise1 = Promise.resolve(3);
var promise2 = hello();
var promise3 = helloThere();
var promise4 = new Promise(function(resolve, reject) {
setTimeout(resolve, 100, 'foo');
});
var promise5 = beers();
async function testThis() {
Promise.all([promise1, promise2, promise3, promise4, promise5]).then(function([result1, result2, result3, result4, result5]) {
console.log(result1);
console.log(result2);
console.log(result3);
console.log(result4);
console.log(result5);
});
return 1;
}
testThis().then(result => console.log(result));
console.log('hey');
/*
> "hey"
> 1
> 3
> "hello"
> "helloThere"
> "foo"
> "[{"id":1,"name":"Buzz","tagline":"A Real Bitter Experience.","first_brewed":"09/2007","description":"A light, crisp and bitter IPA brewed with English and American hops. A small batch brewed only once.","image_url":"https://images.punkapi.com/v2/keg.png","abv":4.5,"ibu":60,"target_fg":1010,"target_og":1044,"ebc":20,"srm":10,"ph":4.4,"attenuation_level":75,"volume":{"value":20,"unit":"liters"},"boil_volume":{"value":25,"unit":"liters"},"method":{"mash_temp":[{"temp":{"value":64,"unit":"celsius"},"duration":75}],"fermentation":{"temp":{"value":19,"unit":"celsius"}},"twist":null},"ingredients":{"malt":[{"name":"Maris Otter Extra Pale","amount":{"value":3.3,"unit":"kilograms"}},{"name":"Caramalt","amount":{"value":0.2,"unit":"kilograms"}},{"name":"Munich","amount":{"value":0.4,"unit":"kilograms"}}],"hops":[{"name":"Fuggles","amount":{"value":25,"unit":"grams"},"add":"start","attribute":"bitter"},{"name":"First Gold","amount":{"value":25,"unit":"grams"},"add":"start","attribute":"bitter"},{"name":"Fuggles","amount":{"value":37.5,"unit":"grams"},"add":"middle","attribute":"flavour"},{"name":"First Gold","amount":{"value":37.5,"unit":"grams"},"add":"middle","attribute":"flavour"},{"name":"Cascade","amount":{"value":37.5,"unit":"grams"},"add":"end","attribute":"flavour"}],"yeast":"Wyeast 1056 - American Ale™"},"food_pairing":["Spicy chicken tikka masala","Grilled chicken quesadilla","Caramel toffee cake"],"brewers_tips":"The earthy and floral aromas from the hops can be overpowering. Drop a little Cascade in at the end of the boil to lift the profile with a bit of citrus.","contributed_by":"Sam Mason <samjbmason>"}]"
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment