'use strict';
const callMock = (object) => new Promise((resolve) => setTimeout(() => resolve(object), 500));
const print = (method, petOne, petTwo) => {
console.log(`Method: ${method}`);
console.log(`PetOne: ${JSON.stringify(petOne)}`);
console.log(`PetTwo: ${JSON.stringify(petTwo)}`);
};
// async / await
const asyncCall = async () => {
const [petOne, petTwo] = await Promise.all([callMock({ pet: 'dog' }), callMock({ pet: 'cat' })]);
print('async / await', petOne, petTwo);
};
asyncCall();
// then
Promise.all([callMock({ pet: 'dog' }), callMock({ pet: 'cat' })])
.then(([petOne, petTwo]) => print('then', petOne, petTwo));
Created
February 27, 2018 20:22
-
-
Save onildoaguiar/c864e179955a3de01f6ea671ad463f88 to your computer and use it in GitHub Desktop.
Example of Promise.all with destructuring
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment