当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript timer.setInterval函数代码示例

本文整理汇总了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");
}
开发者ID:sitefinitysteve,项目名称:NativeScript,代码行数:11,代码来源:timer-tests.ts

示例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
};
开发者ID:sitefinitysteve,项目名称:NativeScript,代码行数:15,代码来源:timer-tests.ts

示例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);
};
开发者ID:sitefinitysteve,项目名称:NativeScript,代码行数:15,代码来源:timer-tests.ts

示例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
};
开发者ID:sitefinitysteve,项目名称:NativeScript,代码行数:18,代码来源:timer-tests.ts

示例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
};
开发者ID:NathanWalker,项目名称:NativeScript,代码行数:20,代码来源:timer-tests.ts


注:本文中的tns-core-modules/timer.setInterval函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。