# clearTimeout not function

**URL:** <https://discourse.nodered.org/t/cleartimeout-not-function/90870>\
**Category:** General\
**Tags:** function-node\
**Created:** [10 September 2024 19:50 UTC](https://discourse.nodered.org/t/cleartimeout-not-function/90870 "2024-09-10T19:50:55Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [10 September 2024 20:02 UTC](https://discourse.nodered.org/t/cleartimeout-not-function/90870/3 "2024-09-10T20:02:27Z")

</div>

> [@Steve-Mcl](#):
>
> You _can_ do this with context (to store the timer handle)

Like this @wilson2517 ...

```auto
var entrada = msg.payload;
var testset = context.get("testset"); // Retrieve the stored timeout reference

if (entrada == "on") {
    testset = setTimeout(function() {
        msg.payload = "active";
        node.send(msg);
    }, 2000);

    context.set("testset", testset); // Store the timeout reference for future use
}

if (entrada == "off") {
    clearTimeout(testset); // Clear the timeout
    context.set("testset", null); // Clear the stored timeout reference
}

```

---

_[View the full topic](https://discourse.nodered.org/t/cleartimeout-not-function/90870)._
