> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/async/await/promises/parallel.md).

# await in parallel

[JS](/web/js.md) ⟩ [async](/web/js/async.md) ⟩ [await](/web/js/async/await.md) ⟩ [promises](/web/js/async/await/promises.md) ⟩ in parallel&#x20;

{% hint style="success" %}
await promises <mark style="color:orange;">**in parallel**</mark>.
{% endhint %}

{% tabs %}
{% tab title="💈範例" %}

* replit：[awaiting multiple promises](https://replit.com/@pegasusroe/awaiting-multiple-promises-in-parallelseries#index.js),  require： [measureTime()](/web/js/async/async/measuretime.md), [futureValue()](/web/js/async/promise/custom-promises/futurevalue.md)

```javascript
async function g() {
    const p1 = futureValue(1, 2);    // in 2 sec
    const p2 = futureValue(2, 4);    // in 4 sec
    return await p1 + await p2;                     // ⭐ await in parallel
}

async function h() {
    const p1 = futureValue(7, 2);    // in 2 sec
    const p2 = futureValue(8, 4);    // in 4 sec
    const [r1, r2] = await Promise.all([p1, p2]);    // ⭐ await in parallel
    return r1 + r2;
}
```

* results

```javascript
measureTime(g);        // ⭐ 4.00 sec : g() -> 3
measureTime(h);        // ⭐ 4.00 sec : h() -> 15
```

{% endtab %}

{% tab title="👥 相關" %}

* [Promises in parallel](/web/js/async/promise/in-parallel.md)
* [chaining Promises](/web/js/async/promise/chaining.md) (in series)
  {% endtab %}

{% tab title="📗 參考" %}

* JS.info ⟩ [async/await](https://javascript.info/async-await)
  {% endtab %}
  {% endtabs %}
