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


TypeScript backburner.cancel函數代碼示例

本文整理匯總了TypeScript中backburner.cancel函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript cancel函數的具體用法?TypeScript cancel怎麽用?TypeScript cancel使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了cancel函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: foo

  let bar = () => {
    assert.ok(true, 'bar called');
    let timer = foo();
    bb.cancel(timer);

    setTimeout(done, 10);
  };
開發者ID:ebryn,項目名稱:backburner.js,代碼行數:7,代碼來源:debounce-test.ts

示例2:

  bb.run(() => {
    let timer = bb.scheduleOnce('one', () => functionWasCalled = true);

    assert.ok(timer, 'Timer object was returned');
    assert.ok(bb.cancel(timer), 'Cancel returned true');
    assert.ok(!functionWasCalled, 'function was not called');
  });
開發者ID:ebryn,項目名稱:backburner.js,代碼行數:7,代碼來源:cancel-test.ts

示例3: function

QUnit.test('setTimeout and creating a new later', function(assert) {
  assert.expect(7);
  let done = assert.async();
  let called = false;
  let bb = new Backburner(['one'], {
    onBegin() {
      called = true;
    }
  });
  let function1WasCalled = false;
  let function2WasCalled = false;

  let timer1 = bb.later(() => function1WasCalled = true, 0);

  assert.ok(timer1, 'Timer object 2 was returned');
  assert.ok(bb.cancel(timer1), 'Cancel for timer 1 returned true');

  let timer2 = bb.later(() => function2WasCalled = true, 1);

  assert.ok(timer2, 'Timer object 2 was returned');
  assert.ok(!called, 'onBegin was not called');

  setTimeout(() => {
    assert.ok(!function1WasCalled, 'function 1 was not called');
    assert.ok(function2WasCalled, 'function 2 was called');
    assert.ok(called, 'onBegin was called');
    done();
  }, 50);
});
開發者ID:ebryn,項目名稱:backburner.js,代碼行數:29,代碼來源:cancel-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: setTimeout

  setTimeout(() => { // 10 millisecond delay
    assert.equal(1, calledCount, 'debounced method was called');
    assert.ok(bb.cancel(timer), 'debounced delay was cancelled');
    bb.debounce(null, debouncee, 1000, true);

    setTimeout(() => { // 10 millisecond delay
      assert.equal(2, calledCount, 'debounced method was called again immediately');
      done();
    }, 10);
  }, 10);
開發者ID:ebryn,項目名稱:backburner.js,代碼行數:10,代碼來源:debounce-test.ts

示例6: setTimeout

  setTimeout(() => {
    assert.ok(!wasCalled, 'attempt to call throttle again didn\'t happen');

    throttle = bb.throttle(null, throttler, 40);
    assert.ok(wasCalled, 'newly inserted throttle after timeout functioned');

    assert.ok(bb.cancel(throttle), 'wait time of throttle was cancelled');

    wasCalled = false;
    throttle2 = bb.throttle(null, throttler, 40);
    assert.notEqual(throttle, throttle2, 'the throttle is different');
    assert.ok(wasCalled, 'throttle was inserted and run immediately after cancel');
    done();
  }, 60);
開發者ID:ebryn,項目名稱:backburner.js,代碼行數:14,代碼來源:throttle-test.ts

示例7: function

QUnit.test('throttle returns timer information usable for cancelling', function(assert) {
  assert.expect(3);

  let done = assert.async();
  let bb = new Backburner(['batman']);
  let wasCalled = false;

  function throttler() {
    assert.ok(false, 'this method shouldn\'t be called');
    wasCalled = true;
  }

  let timer = bb.throttle(null, throttler, 1, false);

  assert.ok(bb.cancel(timer), 'the timer is cancelled');

  // should return false second time around
  assert.ok(!bb.cancel(timer), 'the timer no longer exists in the list');

  setTimeout(() => {
    assert.ok(!wasCalled, 'the timer wasn\'t called after waiting');
    done();
  }, 60);
});
開發者ID:ebryn,項目名稱:backburner.js,代碼行數:24,代碼來源:throttle-test.ts

示例8: done

  bb.schedule('ohai', null, () => {
    assert.ok(!bb.hasTimers(), 'Initially there are no timers');

    timer = bb.later('ohai', () => {});
    assert.ok(bb.hasTimers(), 'hasTimers checks timers');

    bb.cancel(timer);

    assert.ok(!bb.hasTimers(), 'Timers are cleared');

    timer = bb.debounce(target, 'fn', 200);
    assert.ok(bb.hasTimers(), 'hasTimers checks debouncees');

    bb.cancel(timer);
    assert.ok(!bb.hasTimers(), 'Timers are cleared');

    timer = bb.throttle(target, 'fn', 200);
    assert.ok(bb.hasTimers(), 'hasTimers checks throttlers');

    bb.cancel(timer);
    assert.ok(!bb.hasTimers(), 'Timers are cleared');

    done();
  });
開發者ID:ebryn,項目名稱:backburner.js,代碼行數:24,代碼來源:bb-has-timers-test.ts

示例9: function

QUnit.test('boundRunExpiredTimers is called once when first timer canceled', function(assert) {
  let done = assert.async(1);

  let bb = new Backburner(['one']);

  let timer = bb.later(function() {}, 500);
  bb.cancel(timer);

  let boundRunExpiredTimers = bb['_boundRunExpiredTimers'];
  bb['_boundRunExpiredTimers'] = function() {
    assert.ok(true);
    done();
    return boundRunExpiredTimers.apply(bb, arguments);
  };

  bb.later(function() {}, 800);
});
開發者ID:ebryn,項目名稱:backburner.js,代碼行數:17,代碼來源:later-test.ts


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