Merge pull request #818 from NativeScript/atanasovg/timer-fix

Fix #817
This commit is contained in:
Vladimir Enchev
2015-09-30 16:28:01 +03:00
2 changed files with 6 additions and 5 deletions

View File

@@ -136,8 +136,7 @@ export var test_setInterval_callbackCalledDuringPeriod = function () {
export var test_setInterval_callbackShouldBeCleared = function () {
var counter = 0;
var expected = 1;
var isReady = function () { return counter === expected; }
var isReady = function () { return false; }
// <snippet module="timer" title="timer">
// ### Cancel the interval previously started using the setInterval method.
@@ -152,5 +151,5 @@ export var test_setInterval_callbackShouldBeCleared = function () {
// </snippet>
TKUnit.waitUntilReady(isReady, 0.5);
TKUnit.assert(isReady(), "Callback should be raised only once!");
};
TKUnit.assert(counter === 1, "Callback should be raised only once!");
};

View File

@@ -50,7 +50,9 @@ export function setInterval(callback: Function, milliseconds = 0): number {
var runnable = new java.lang.Runnable({
run: () => {
callback();
handler.postDelayed(runnable, long(milliseconds));
if (timeoutCallbacks[id]) {
handler.postDelayed(runnable, long(milliseconds));
}
}
});