> 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/promise/custom-promises/promise.wait.md).

# Promise.wait()

{% tabs %}
{% tab title="💾 程式" %}
:floppy\_disk: replit：[Promise.wait()](https://replit.com/@pegasusroe/Promise-wait#index.js)

```javascript
// ⭐ Promise.wait()
Promise.wait = function(seconds) {
    return new Promise((resolve, _) => {    // this Promise never rejects.
        // do not wait if `seconds` not positive.
        if (!(seconds > 0)) seconds = 0;
        // invoking resolve() with no arguments means 
        // that the Promise will always fulfill with value `undefined`.
        setTimeout(resolve, seconds * 1000);
    });
};
```

💈範例：

```javascript
Promise
    .wait(2)                            // wait for 2 seconds
    .then(_ => console.log('hello'));
```

{% endtab %}

{% tab title="📘 手冊" %}

* [Promise() constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise) - make Promise from scratch.
  {% endtab %}
  {% endtabs %}
