本文整理汇总了TypeScript中timer/timer.setTimeout函数的典型用法代码示例。如果您正苦于以下问题:TypeScript setTimeout函数的具体用法?TypeScript setTimeout怎么用?TypeScript setTimeout使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setTimeout函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
export var test_setTimeout_callbackShouldBeCleared = function () {
// This test is very unstable in iOS, because the platform does not guarantee the
// callback will be cleared on time. Better skip it for iOS.
if (platform.device.os === platform.platformNames.ios) {
return;
}
var completed: boolean;
var isReady = function () { return completed; }
// <snippet module="timer" title="timer">
// ### Cancels the evaluation with the clearTimeout method.
// ``` JavaScript
var id = timer.setTimeout(function () {
// <hide>
completed = true;
// </hide>
}, 2000);
//// Clear timeout with specified id.
timer.clearTimeout(id);
// ```
// </snippet>
TKUnit.waitUntilReady(isReady, 3);
TKUnit.assert(!completed, "Callback should be cleared when clearTimeout() is executed for specified id!");
};
示例2: function
export var test_setTimeout_callbackNotCalled = function () {
var completed: boolean;
var isReady = function () { return completed; }
timer.setTimeout(function () {
completed = true;
}, 1000);
TKUnit.waitUntilReady(isReady, 0.5);
TKUnit.assert(!completed, "Callback should be called after specified time!");
};