本文整理汇总了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
};