Skip to content

Instantly share code, notes, and snippets.

View PabloHidalgo's full-sized avatar

Pablo Hidalgo Vaquerizas PabloHidalgo

  • Sngular
  • Madrid
View GitHub Profile
@PabloHidalgo
PabloHidalgo / 1-sleep-es7.js
Created March 7, 2018 10:53 — forked from danharper/1-sleep-es7.js
ES7's async/await syntax.
// ES7, async/await
function sleep(ms = 0) {
return new Promise(r => setTimeout(r, ms));
}
(async () => {
console.log('a');
await sleep(1000);
console.log('b');
})()
@PabloHidalgo
PabloHidalgo / async-await.js
Created March 7, 2018 10:52 — forked from wesbos/async-await.js
Simple Async/Await Example
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works
const axios = require('axios'); // promised based requests - like fetch()
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}