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
17 changes: 17 additions & 0 deletions tests/app/timer/timer-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ export function test_setTimeout_callbackCalledAfterSpecifiedTime() {
TKUnit.assert(completed, "Callback should be called after the specified time!");
}

export function test_setTimeout_callbackCalledWithBooleanPeriod() {
let completed = false;

// >> timer-set-false
const id = timer.setTimeout(() => {
// >> (hide)
completed = true;
// << (hide)
// @ts-ignore
}, false);
// << timer-set-false

TKUnit.waitUntilReady(() => completed, 1);
timer.clearTimeout(id);
TKUnit.assert(completed, "Callback should be called in 0 seconds!");
}

export function test_setTimeout_callbackNotCalled() {
let completed = false;

Expand Down
6 changes: 6 additions & 0 deletions tns-core-modules/timer/timer.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ function createHandlerAndGetId(): number {
}

export function setTimeout(callback: Function, milliseconds = 0, ...args): number {
// Cast to Number
milliseconds += 0;

const id = createHandlerAndGetId();
const invoke = () => callback(...args);
const zoneBound = zonedCallback(invoke);
Expand Down Expand Up @@ -48,6 +51,9 @@ export function clearTimeout(id: number): void {
}

export function setInterval(callback: Function, milliseconds = 0, ...args): number {
// Cast to Number
milliseconds += 0;

const id = createHandlerAndGetId();
const handler = timeoutHandler;
const invoke = () => callback(...args);
Expand Down
3 changes: 3 additions & 0 deletions tns-core-modules/timer/timer.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class TimerTargetImpl extends NSObject {
}

function createTimerAndGetId(callback: Function, milliseconds: number, shouldRepeat: boolean): number {
// Cast to Number
milliseconds += 0;

timerId++;
let id = timerId;
let timerTarget = TimerTargetImpl.initWithCallback(callback, id, shouldRepeat);
Expand Down