mirror of
https://github.com/apricote/presentations.git
synced 2026-01-13 21:11:02 +00:00
asyncJs: fix Promise.all Array param
This commit is contained in:
parent
5884611e0a
commit
a09cbdd677
1 changed files with 5 additions and 5 deletions
|
|
@ -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) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue