asyncJs: fix Promise.all Array param

This commit is contained in:
Julian Tölle 2017-12-12 22:09:31 +01:00
parent 5884611e0a
commit a09cbdd677

View file

@ -163,10 +163,10 @@
</h4> </h4>
<pre><code class="js" data-trim> <pre><code class="js" data-trim>
// Parallel Execution // Parallel Execution
Promise.all( Promise.all([
fetch("https://api.coindesk.com/v1/bpi/currentprice.json"), fetch("https://api.coindesk.com/v1/bpi/currentprice.json"),
fetch("https://api.coindesk.com/v1/bpi/historical/close.json") fetch("https://api.coindesk.com/v1/bpi/historical/close.json")
).then(([currentPrice, historicalPrices]) => ]).then(([currentPrice, historicalPrices]) =>
console.log(currentPrice, historicalPrices) console.log(currentPrice, historicalPrices)
).catch(err => console.error(err)); ).catch(err => console.error(err));
</code></pre> </code></pre>
@ -177,7 +177,7 @@
<pre><code class="js" data-trim> <pre><code class="js" data-trim>
// Variable Passthrough // Variable Passthrough
User.findOne({ name: "realDonaldTrump" }) User.findOne({ name: "realDonaldTrump" })
.then(user => Promise.all(user, Tweets.find({ user_id: user.id }))) .then(user => Promise.all([user, Tweets.find({ user_id: user.id })]))
.then(([user, tweets]) => { .then(([user, tweets]) => {
console.log(`User ${user.name} has ${tweets.length} tweets`); console.log(`User ${user.name} has ${tweets.length} tweets`);
}); });
@ -221,10 +221,10 @@
// Parallel Execution // Parallel Execution
async function getBtcData() { async function getBtcData() {
try { try {
const [currentPrice, historicalPrices] = await Promise.all( const [currentPrice, historicalPrices] = await Promise.all([
fetch("https://api.coindesk.com/v1/bpi/currentprice.json"), fetch("https://api.coindesk.com/v1/bpi/currentprice.json"),
fetch("https://api.coindesk.com/v1/bpi/historical/close.json") fetch("https://api.coindesk.com/v1/bpi/historical/close.json")
) ])
console.log(currentPrice, historicalPrices) console.log(currentPrice, historicalPrices)
} catch (err) { } catch (err) {