当前位置: 首页>>代码示例>>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;未经允许,请勿转载。