[TIMOB-525] clearTimeout triggers the call instead of just clearing
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-04-17T01:53:23.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 1.4.0 |
Components | iOS |
Labels | mobile, settimeout |
Reporter | Jae Hess |
Assignee | Reggie Seagraves |
Created | 2011-04-15T02:31:00.000+0000 |
Updated | 2011-04-17T01:53:23.000+0000 |
Description
Comments
- 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:
- Click "move"
- move a row. This sets a timeout to fire in 20 seconds.
- 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.
- Click "move"
- 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);
- 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; } - 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...