Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions apps/automated/src/timer/timer-tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as TKUnit from '../tk-unit';
import * as timer from '@nativescript/core/timer';
import { Utils } from '@nativescript/core';

// >> timer-require
// require("globals");
Expand Down Expand Up @@ -51,7 +52,7 @@ export function test_setTimeout_extraArgs() {
// << (hide)
},
0,
rnd
rnd,
);
// << timer-set-zero-args

Expand Down Expand Up @@ -152,6 +153,25 @@ export function test_setInterval_callbackCalledDuringPeriod(done) {
// << timer-set-expression
}

export function test_setInterval_keepsFiringAcrossGarbageCollection(done) {
let counter = 0;
const id = timer.setInterval(() => {
counter++;
if (counter === 2) {
for (let i = 0; i < 3; i++) {
Utils.GC();
if (__ANDROID__) {
java.lang.System.gc();
java.lang.System.runFinalization();
}
}
} else if (counter === 4) {
timer.clearInterval(id);
done(null);
}
}, 20);
}

export function test_setInterval_callbackCalledWithExtraArgs(done) {
let counter: number = 0;
const rnd: number = Math.random();
Expand All @@ -168,7 +188,7 @@ export function test_setInterval_callbackCalledWithExtraArgs(done) {
}
},
250,
rnd
rnd,
);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/core/timer/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export function setInterval(callback: Function, milliseconds = 0, ...args): numb
}

const delay = Math.max(0, nextDueTime - now);
handler.postDelayed(runnable, long(delay));
// Not the enclosing `runnable`: a closure over it is a cycle through the runnable's native counterpart.
handler.postDelayed(timeoutCallbacks[id], long(delay));
}
},
});
Expand Down
Loading