# 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/web/js/async/await/promises/parallel.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
