當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。