# Promise.timeout()

**URL:** <https://es.discourse.group/t/promise-timeout/236>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [February 24, 2020, 9:27pm UTC](https://es.discourse.group/t/promise-timeout/236 "2020-02-24T21:27:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmm211](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@mmm211](https://es.discourse.group/u/mmm211)\
**Post date:** [February 24, 2020, 9:27pm UTC](https://es.discourse.group/t/promise-timeout/236/1 "2020-02-24T21:27:37Z")

</div>

There should be a `timeout()` or `delay()` method on the `Promise` object for a cleaner way to add a delay in an async code block.

`await Promise.timeout(1000);`

equivalent to

`await new Promise(t => setTimeout(t, 1000));`

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [February 24, 2020, 11:15pm UTC](https://es.discourse.group/t/promise-timeout/236/2 "2020-02-24T23:15:44Z")

</div>

`setTimeout` isn't in the language, however, and I suspect there will be a lot of pushback if adding any kind of "timer" is attempted.

---

<div class="post-metadata">

**Author:** ![kaizhu256](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kaizhu256/32/342_2.png) [@kaizhu256](https://es.discourse.group/u/kaizhu256)\
**Post date:** [February 25, 2020, 4:06pm UTC](https://es.discourse.group/t/promise-timeout/236/3 "2020-02-25T16:06:02Z")

</div>

> `setTimeout` isn't in the language, however, and I suspect there will be a lot of pushback if adding any kind of "timer" is attempted.

+1 to standardize setTimeout among engines and Promise.timeout if possible.

duktape has example-implementation of eventloop/setTimeout in pure javascript which could serve as polyfill [1]. even if engines implement it suboptimally (duktape example is O(n) timer-insertion), its still better than not having setTimeout at all.

[1] Pure ECMAScript eventloop example

> <https://github.com/svaarala/duktape/blob/4e728b875c6b2756e94a52ff4d0d3957210b3f79/examples/eventloop/ecma_eventloop.js>
