當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript backburner.scheduleOnce函數代碼示例

本文整理匯總了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);
  });
開發者ID:ebryn,項目名稱:backburner.js,代碼行數:10,代碼來源:cancel-test.ts

示例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();
  });
});
開發者ID:ebryn,項目名稱:backburner.js,代碼行數:31,代碼來源:configurable-timeout-test.ts

示例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);
 });
開發者ID:ebryn,項目名稱:backburner.js,代碼行數:9,代碼來源:defer-once-test.ts

示例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');

});
開發者ID:ebryn,項目名稱:backburner.js,代碼行數:46,代碼來源:multi-turn-test.ts

示例5: Error

 bb.run(() => {
   bb.scheduleOnce('errors', () => {
     throw new Error('QUnit.test error');
   });
 });
開發者ID:ebryn,項目名稱:backburner.js,代碼行數:5,代碼來源:defer-once-test.ts

示例6:

 bb.run(() => {
   bb.scheduleOnce('one', argObj, deferMethod, 1);
   bb.scheduleOnce('two', argObj, scheduleMethod);
 });
開發者ID:ebryn,項目名稱:backburner.js,代碼行數:4,代碼來源:defer-once-test.ts

示例7: scheduleMethod

 function scheduleMethod() {
   bb.scheduleOnce('one', argObj, deferMethod, 2);
 }
開發者ID:ebryn,項目名稱:backburner.js,代碼行數:3,代碼來源:defer-once-test.ts

示例8:

 bb.run(() => {
   bb.scheduleOnce('one', () => {
     assert.ok(!functionWasCalled, 'function was not called');
     assert.ok(customClearTimeoutWasUsed, 'custom clearTimeout was used');
   });
 });
開發者ID:ebryn,項目名稱:backburner.js,代碼行數:6,代碼來源:configurable-timeout-test.ts


注:本文中的backburner.scheduleOnce函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。