Sha256: e98673c99d856f0073153e874f6720a5076579af7da56616eee100fed283c3d7

Contents?: true

Size: 1.59 KB

Versions: 3

Compression:

Stored size: 1.59 KB

Contents

import { run, next, getCurrentRunLoop } from '..';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

moduleFor(
  'run.next',
  class extends AbstractTestCase {
    ['@test should invoke immediately on next timeout'](assert) {
      let done = assert.async();
      let invoked = false;

      run(() => next(() => (invoked = true)));

      assert.equal(invoked, false, 'should not have invoked yet');

      setTimeout(() => {
        assert.equal(invoked, true, 'should have invoked later item');
        done();
      }, 20);
    }

    ['@test callback should be called from within separate loop'](assert) {
      let done = assert.async();
      let firstRunLoop, secondRunLoop;
      run(() => {
        firstRunLoop = getCurrentRunLoop();
        next(() => (secondRunLoop = getCurrentRunLoop()));
      });

      setTimeout(() => {
        assert.ok(secondRunLoop, 'callback was called from within run loop');
        assert.ok(
          firstRunLoop && secondRunLoop !== firstRunLoop,
          'two separate run loops were invoked'
        );
        done();
      }, 20);
    }

    ['@test multiple calls to next share coalesce callbacks into same run loop'](assert) {
      let done = assert.async();
      let secondRunLoop, thirdRunLoop;
      run(() => {
        next(() => (secondRunLoop = getCurrentRunLoop()));
        next(() => (thirdRunLoop = getCurrentRunLoop()));
      });

      setTimeout(() => {
        assert.ok(
          secondRunLoop && secondRunLoop === thirdRunLoop,
          'callbacks coalesced into same run loop'
        );
        done();
      }, 20);
    }
  }
);

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
discourse-ember-source-3.6.0.0 dist/es/@ember/runloop/tests/next_test.js
discourse-ember-source-3.5.1.1 dist/es/@ember/runloop/tests/next_test.js
discourse-ember-source-3.5.1.0 dist/dist/es/@ember/runloop/tests/next_test.js