# Timers extension: after X, debounce, throttle, and in-background

**URL:** <https://forum.makecode.com/t/timers-extension-after-x-debounce-throttle-and-in-background/1925>\
**Category:** Arcade\
**Tags:** extension\
**Created:** [May 2, 2020, 7:53pm UTC](https://forum.makecode.com/t/timers-extension-after-x-debounce-throttle-and-in-background/1925 "2020-05-02T19:53:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![darzu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/darzu/32/1882_2.png) [@darzu](https://forum.makecode.com/u/darzu)\
**Post date:** [May 2, 2020, 7:53pm UTC](https://forum.makecode.com/t/timers-extension-after-x-debounce-throttle-and-in-background/1925/1 "2020-05-02T19:53:56Z")

</div>

Hello world,

I create a new “Timers” extension: [https://github.com/darzu/arcade-timers](https://github.com/darzu/arcade-timers)  
Early beta.

Sample: [https://makecode.com/\_c57bYTea0RFV](https://makecode.com/_c57bYTea0RFV)

## Blocks

 ![Screen Shot 2020-05-02 at 12.35.02 PM](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/266bba788051e4f2590309656b25c61ce3a2f8ac.png)

## Examples

#### “After X do” / aka setTimeout:

 ![2020-05-02 12.33.39](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/9302a9b1d40cb3c3519e3ee9b373cff46a8ec6f1.gif)

#### “Separately do” / aka run in background thread:

 ![2020-05-02 12.33.56](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/2279b1075112eae10b5861bbee0e26bf31712d30.gif)

#### “after Y settled for X do” / aka debounce:

 ![2020-05-02 12.34.16](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/d16b80463f90b10561e16ebd5f9931d1d6f4d84b.gif)

#### “for Y at most once every X do” / aka throttle:

 ![2020-05-02 12.34.47](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/8c69c7612ff407785725cfa3935b2013381e256e.gif)

---

<div class="post-metadata">

**Author:** ![jacob\_c](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jacob_c/32/1532_2.png) [@jacob\_c](https://forum.makecode.com/u/jacob_c)\
**Post date:** [May 2, 2020, 9:13pm UTC](https://forum.makecode.com/t/timers-extension-after-x-debounce-throttle-and-in-background/1925/2 "2020-05-02T21:13:11Z")

</div>

Oooh. These look nice! I’m curious if there are many implementation differences between your `setTimeout` equivalent and @peli’s recently posted `setTimeout`-sounding block:

> [@"run on game update after" extension](https://forum.makecode.com/t/run-on-game-update-after-extension/1772):
>
> This is a single block extension that allows to schedule code execution after a delay, in the game update. [https://pelikhan.github.io/arcade-clock/](https://pelikhan.github.io/arcade-clock/) [image]

---

<div class="post-metadata">

**Author:** ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)\
**Post date:** [May 2, 2020, 9:58pm UTC](https://forum.makecode.com/t/timers-extension-after-x-debounce-throttle-and-in-background/1925/3 "2020-05-02T21:58:22Z")

</div>

My APIs are integrated into the arcade runtime, eg they will run at the same priority as the “on game update” handler.

---

<div class="post-metadata">

**Author:** ![jacob\_c](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jacob_c/32/1532_2.png) [@jacob\_c](https://forum.makecode.com/u/jacob_c)\
**Post date:** [May 2, 2020, 11:43pm UTC](https://forum.makecode.com/t/timers-extension-after-x-debounce-throttle-and-in-background/1925/4 "2020-05-02T23:43:16Z")

</div>

Ah. I should probably learn more about this.

Is this documentation still mostly relevant? [https://arcade.makecode.com/developer/game-loop](https://arcade.makecode.com/developer/game-loop) … the version number mentioned in the beginning looks to be a bit behind the current release.

---

<div class="post-metadata">

**Author:** ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)\
**Post date:** [May 5, 2020, 4:17am UTC](https://forum.makecode.com/t/timers-extension-after-x-debounce-throttle-and-in-background/1925/5 "2020-05-05T04:17:24Z")

</div>

Yes it’s pretty good. This part has not changed much.
