Skip to content

Instantly share code, notes, and snippets.

@mkjiau
Created July 11, 2017 19:30
Show Gist options
  • Save mkjiau/9172bb0a8a2c7499d6ee3272ed7b4a5c to your computer and use it in GitHub Desktop.
Save mkjiau/9172bb0a8a2c7499d6ee3272ed7b4a5c to your computer and use it in GitHub Desktop.
var apif1 = () => new Promise((resolve, reject) => {
setTimeout(resolve, 1000, "one");
});
var apif2 = () => new Promise((resolve, reject) => {
setTimeout(resolve, 2000, "two");
});
var apif3 = (values) => new Promise((resolve, reject) => {
var flattened = values.reduce((acc, val) => acc.concat(val));
setTimeout(resolve, 3000, flattened);
});
const combineTwo = async () => {
const r1 = await apif1();
const r2 = await apif2();
const r3 = await apif3([r1, r2]);
console.log(r3);
};
combineTwo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment