Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. [gelöst] clearTimeout -> Prüfen ob Timeout gesetzt ist?

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    [gelöst] clearTimeout -> Prüfen ob Timeout gesetzt ist?

    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      baeckerman83 last edited by

      Wie kann ich prüfen ob ein Timeot gesetzt ist?

      Ich habe:

      var timeoutVar=false;
      var power=0;
      
      on("hm-rpc.POWER", function (obj) {
      	if(power<10){
       		if(!timeoutVar){
        			timeoutVar=setTimeout(function(){console.log("warte");},50000);
        		}
       	}else{
        		clearTimeout(timeoutVar);
       	}
      }
      console.log(timeoutVar);
      

      Mein Problem ist, auch nach clearTimeout ist console.log(timeoutVar); ein [object Object]

      was mache ich falsch? Ich dachte mit clearTimeout wird das dann null oder wenigstens false.

      1 Reply Last reply Reply Quote 0
      • paul53
        paul53 last edited by

        Timervariablen sind Objekte. Deshalb sollte man sie so anwenden:

        var timeoutVar = null;
        
        on("hm-rpc.POWER", function (obj) {
           if(obj.state.val < 10){
               timeoutVar = setTimeout(function(){
                   console.log("Zeit abgelaufen");
                   timeoutVar = null;
               }, 50000);
           } else if(timeoutVar) {
               clearTimeout(timeoutVar);
               timeoutVar = null;
           }
           if(timeoutVar) console.log('Timer läuft');
        });
        
        
        1 Reply Last reply Reply Quote 1
        • B
          baeckerman83 last edited by

          Ah ok, dann setze ich das immer auf null.

          Hatte in der Docu geschaut und da war das Beispiel immer ohne auf null setzen.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          Support us

          ioBroker
          Community Adapters
          Donate

          462
          Online

          31.7k
          Users

          79.8k
          Topics

          1.3m
          Posts

          2
          3
          1499
          Loading More Posts
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes
          Reply
          • Reply as topic
          Log in to reply
          Community
          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
          The ioBroker Community 2014-2023
          logo