Skip to content

Instantly share code, notes, and snippets.

View guillefd's full-sized avatar
🤖
Building

Guillermo guillefd

🤖
Building
View GitHub Profile
@guillefd
guillefd / javascript-promise-timeout.js
Created February 18, 2018 14:59 — forked from john-doherty/javascript-promise-timeout.js
Adds a timeout to a JavaScript promise, rejects if not resolved within timeout period
/**
* 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(){
@guillefd
guillefd / async-await.js
Created April 3, 2018 18:18 — 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
});
}
@guillefd
guillefd / async2.js
Last active January 30, 2019 13:52 — forked from bmorelli25/async2.js
Async/Await Example
/// EXAMPLE 1
function resolveAfter2Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}