Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p><em>"Is there a way to check of clearTimeout was successful."</em></p> </blockquote> <p>No, there's no state maintained that you can check, but if you manage your timers properly, it shouldn't be an issue.</p> <hr> <p>You could create your own stateful timer object I suppose...</p> <pre><code>var _slice = Array.prototype.slice; // substitute for setTimeout function myTimer(fn,ms) { var args = _slice.call(arguments,2), timer_state = { complete: false, timer: setTimeout(function() { timer_state.complete = true; fn.apply(this, args); }, ms) }; return timer_state; }; // substitute for clearTimeout function clearMyTimer(timer_obj) { timer_obj.complete = true; clearTimeout(timer_obj.timer); }; </code></pre> <p>Example of clearing the timer...</p> <pre><code> // create a timer var timer = myTimer( function() { console.log('timer is done'); }, 1000); console.log( timer.complete ); // complete? false clearMyTimer( timer ); // clear it console.log( timer.complete ); // complete? true </code></pre> <p>Example of letting it run...</p> <pre><code> // create a timer var timer = myTimer( function() { console.log('timer is done'); }, 1000); console.log( timer.complete ); // complete? false // check the timer object after it has expired setTimeout(function() { console.log( timer.complete ); // complete? true }, 1500); </code></pre> <hr> <p><em>EDIT: Updated to make <code>this</code> consistent in strict mode, and to support additional argument passed through to the callback. Thanks to <a href="https://stackoverflow.com/users/798880/saxoier">@Saxoier</a> for the note.</em></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload