本文整理汇总了TypeScript中backburner.scheduleOnce函数的典型用法代码示例。如果您正苦于以下问题:TypeScript scheduleOnce函数的具体用法?TypeScript scheduleOnce怎么用?TypeScript scheduleOnce使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了scheduleOnce函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
bb.run(() => {
let timer = bb.scheduleOnce('action', fn);
assert.equal(wasCalled, 0);
bb.cancel(timer);
bb.scheduleOnce('action', fn);
assert.equal(wasCalled, 0);
});
示例2: function
QUnit.test('We can use a custom next', function(assert) {
assert.expect(1);
let done = assert.async();
let customNextWasUsed = false;
let bb = new Backburner(['one'], {
_buildPlatform(flush) {
return {
setTimeout() {
throw new TypeError('NOT IMPLEMENTED');
},
clearTimeout(timer) {
return clearTimeout(timer);
},
next() {
// next is used for the autorun
customNextWasUsed = true;
return setTimeout(flush);
},
clearNext() { },
now() { return Date.now(); },
isFakePlatform: true
};
}
});
bb.scheduleOnce('one', () => {
assert.ok(customNextWasUsed , 'custom later was used');
done();
});
});
示例3: function
bb.run(() => {
bb.scheduleOnce('one', {zomg: 'hi'}, function(a, b, c) {
assert.equal(this.zomg, 'hi', 'the target was properly set');
assert.equal(a, 1, 'the first arguments was passed in');
assert.equal(b, 2, 'the second arguments was passed in');
assert.equal(c, 3, 'the third arguments was passed in');
functionWasCalled = true;
}, 1, 2, 3);
});
示例4: function
QUnit.test('properly cancel items which are added during flush', function(assert) {
let bb = new Backburner(['zomg'], {
// This is just a place holder for now, but somehow the system needs to
// know to when to stop
mustYield() {
return true; // yield after each step, for now.
},
_buildPlatform: buildFakePlatform
});
let fooCalled = 0;
let barCalled = 0;
let obj1 = {
foo() {
fooCalled++;
}
};
let obj2 = {
bar() {
barCalled++;
}
};
bb.scheduleOnce('zomg', obj1, 'foo');
bb.scheduleOnce('zomg', obj1, 'foo');
bb.scheduleOnce('zomg', obj2, 'bar');
bb.scheduleOnce('zomg', obj2, 'bar');
platform.flushSync();
let timer1 = bb.scheduleOnce('zomg', obj1, 'foo');
let timer2 = bb.scheduleOnce('zomg', obj2, 'bar');
bb.cancel(timer1);
bb.cancel(timer2);
platform.flushSync();
platform.flushSync();
platform.flushSync();
assert.equal(fooCalled, 1, 'fooCalled');
assert.equal(barCalled, 1, 'barCalled');
});
示例5: Error
bb.run(() => {
bb.scheduleOnce('errors', () => {
throw new Error('QUnit.test error');
});
});
示例6:
bb.run(() => {
bb.scheduleOnce('one', argObj, deferMethod, 1);
bb.scheduleOnce('two', argObj, scheduleMethod);
});
示例7: scheduleMethod
function scheduleMethod() {
bb.scheduleOnce('one', argObj, deferMethod, 2);
}
示例8:
bb.run(() => {
bb.scheduleOnce('one', () => {
assert.ok(!functionWasCalled, 'function was not called');
assert.ok(customClearTimeoutWasUsed, 'custom clearTimeout was used');
});
});