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
// 🔥 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 | |
}); | |
} |
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
/// EXAMPLE 1 | |
function resolveAfter2Seconds() { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve('resolved'); | |
}, 2000); | |
}); | |
} |
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
/** | |
* wraps a promise in a timeout, allowing the promise to reject if not resolve with a specific period of time | |
* @param {integer} ms - milliseconds to wait before rejecting promise if not resolved | |
* @param {Promise} promise to monitor | |
* @Example | |
* promiseTimeout(1000, fetch('https://courseof.life/johndoherty.json')) | |
* .then(function(cvData){ | |
* alert(cvData); | |
* }) | |
* .catch(function(){ |