Skip to content

Instantly share code, notes, and snippets.

@infantito
infantito / parallel-async.js
Last active February 25, 2020 23:35
TIP: When making two asynchronous calls, ask yourself if you want to make those calls in serial or parallel
// code: https://twitter.com/joelnet/status/1231994830798061568
const sum = (a, b) => Promise.resolve(a + b);
const subtract = (a, b) => Promise.resolve(a - b);
// Promises
const promises = async () => {
const p1 = sum(7, 3);
const p2 = sum(8, 5);
return Promise.all([p1, p2]);
@infantito
infantito / ajax-synchronous.js
Created June 11, 2017 20:26
Example of how to get ajax call in a synchronous way
let url = 'https://jsonplaceholder.typicode.com';
let buttonAjax = document.querySelector('.buttonAjax');
buttonAjax.addEventListener('click', doSomething);
function doSomething() {
console.log('do something more...');
return getAjax(callback, 'users', anotherAjax);
}