Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-525] clearTimeout triggers the call instead of just clearing

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T01:53:23.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.4.0
ComponentsiOS
Labelsmobile, settimeout
ReporterJae Hess
AssigneeReggie Seagraves
Created2011-04-15T02:31:00.000+0000
Updated2011-04-17T01:53:23.000+0000

Description

Comments

  1. Noah 2011-04-15

    Here is a reproducible http://gist.github.com/335391">test case.

    Make it your app.js and run it.

    How to reproduce:

    1. Click "move"
    2. move a row. This sets a timeout to fire in 20 seconds.
    3. move another row within 20 seconds. The timeout will fire.

    I realize this could have been a simpler test, but I knew this would reproduce the problem, since this is how I ran into it in the first place.

  2. Nick Wing 2011-04-15

    Here's a stupidly simple broken test case:

       var win = Titanium.UI.createWindow({ backgroundColor:'#fff' });
       win.open();
       var timer = setTimeout(function() { alert('You should never see me!'); }, 5000);
       clearTimeout(timer);
       
  3. Nick Wing 2011-04-15

    Here's a generalized workaround I came up with:

       function timeoutObject() { this.flag = true; }
       function mySetTimeout(callback, time) {
         var myCallback = callback;
         if (typeof callback == 'string') {

       myCallback = function() { eval(callback); };
       
       
       
       
    } var timerobj = new timeoutObject(); setTimeout(function () {
       if (timerobj.flag) { myCallback(); }
       
       
       
       
    }, time); return timerobj; } function myClearTimeout(timer) { timer.flag = false; }
  4. Jeff Haynie 2011-04-15

    (from [3f94bd90743f2c323216909fe50a016a16ea6dcf]) Closes #525: Timers now stop before invocation if cancelled. http://github.com/appcelerator/titanium_mobile/commit/3f94bd90743f2c323216909fe50a016a16ea6dcf"> http://github.com/appcelerator/titanium_mobile/commit/3f94bd90743f2...

JSON Source