Skip to content

Instantly share code, notes, and snippets.

@crates
Last active May 31, 2018 17:35
Show Gist options
  • Save crates/bbcd2686a4648b8371e1f7759882a4b5 to your computer and use it in GitHub Desktop.
Save crates/bbcd2686a4648b8371e1f7759882a4b5 to your computer and use it in GitHub Desktop.
Parallel, asynchronous AJAX calls in ES6
const parallel = async (...items) => {
const temp = [];
for (const item of items) {
temp.push(await item);
}
return temp;
};
const finalResult = await parallel(someResult(), anotherResult());
//or
//const [result1, result2] = await parallel(someResult(), anotherResult());
// Alternative Implementation:
async function stepVerifyIdentity(nextState, replace, callback) {
const [ val1, val2, val3 ] = await Promise.all([
promise1('Param1'),
promise2('Param2'),
promise3('Param3')
])
if (!val1 && (!val2 || !val3)) {
console.log('Do something')
}
}