本文整理匯總了TypeScript中tns-core-modules/timer.setInterval函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript setInterval函數的具體用法?TypeScript setInterval怎麽用?TypeScript setInterval使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了setInterval函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: test_clearInterval_immediatelyAfterCreate
export function test_clearInterval_immediatelyAfterCreate() {
let completed = false;
const id = timer.setInterval(() => {
completed = true;
});
timer.clearInterval(id);
TKUnit.wait(0.05);
TKUnit.assert(!completed, "Callback should not be called");
}
示例2: test_setInterval_callbackShouldBeCleared
export function test_setInterval_callbackShouldBeCleared(done) {
let counter = 0;
const start = TKUnit.time();
// >> timer-set-interval
const id = timer.setInterval(() => {
// >> (hide)
const end = TKUnit.time();
timer.clearInterval(id);
done(end - start > 150 ? new Error('setInterval too slow.') : null);
// << (hide)
timer.clearInterval(id);
}, 50);
// << timer-set-interval
};
示例3: test_setInterval_callbackCalledWithExtraArgs
export function test_setInterval_callbackCalledWithExtraArgs(done) {
let counter: number = 0;
const expected: number = 4;
const rnd: number = Math.random();
const start = TKUnit.time();
const id = timer.setInterval((arg) => {
counter += arg === rnd ? 1 : -1;
if (counter === 4) {
const end = TKUnit.time();
timer.clearInterval(id);
done(end - start > 250 ? new Error('setInterval too slow.') : null);
}
}, 50, rnd);
};
示例4: test_setInterval_callbackCalledDuringPeriod
export function test_setInterval_callbackCalledDuringPeriod(done) {
let counter = 0;
const expected = 4;
const start = TKUnit.time();
// >> timer-set-expression
const id = timer.setInterval(() => {
// >> (hide)
counter++;
if (counter === 4) {
const end = TKUnit.time();
timer.clearInterval(id);
done(end - start > 250 ? new Error('setInterval too slow.') : null);
}
// << (hide)
}, 50);
// << timer-set-expression
};
示例5: test_setInterval_callbackCalledDuringPeriod
export function test_setInterval_callbackCalledDuringPeriod(done) {
let counter = 0;
const expected = 4;
const timeLimit = 300;
const start = TKUnit.time();
// >> timer-set-expression
const id = timer.setInterval(() => {
// >> (hide)
counter++;
if (counter === expected) {
const end = TKUnit.time();
timer.clearInterval(id);
const time = end - start;
done(time > timeLimit ? new Error(`setInterval too slow. Actual time: ${time} timelimit: ${timeLimit}`) : null);
}
// << (hide)
}, 50);
// << timer-set-expression
};