How to use the @aurelia/router.Queue function in @aurelia/router

To help you get started, we’ve selected a few @aurelia/router examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aurelia / aurelia / packages / __tests__ / router / queue.spec.ts View on Github external
it('can be created', function () {
    const q = new Queue((animal: QueueItem) => { });
  });
github aurelia / aurelia / packages / __tests__ / router / queue.spec.ts View on Github external
it('can tick the queue', async function () {
    this.timeout(5000);

    const ctx = TestContext.createHTMLTestContext();
    const { scheduler } = ctx;

    const callback = async (qAnimal: QueueItem) => {
      await wait(100);
      qAnimal.resolve();
    };
    const q = new Queue(callback as (item: QueueItem) => void);
    q.activate({ allowedExecutionCostWithinTick: 0, scheduler });
    let promise = q.enqueue(new Animal('dog', 'Pluto'));
    assert.strictEqual(q.pending.length, 1, `q.pending.length`);
    await wait(50);
    assert.strictEqual(q.pending.length, 0, `q.pending.length`);
    await promise;
    promise = q.enqueue(new Animal('cat', 'Figaro'));
    assert.strictEqual(q.pending.length, 1, `q.pending.length`);
    await wait(120);
    assert.strictEqual(q.pending.length, 0, `q.pending.length`);
    q.deactivate();
  });
});
github aurelia / aurelia / packages / __tests__ / router / queue.spec.ts View on Github external
it('adds to queue', async function () {
    this.timeout(5000);
    const callback = async (qAnimal: QueueItem) => {
      const animal = qAnimal as Animal;
      await wait(100);
      if (animal.name === 'dog') {
        qAnimal.reject();
      } else {
        qAnimal.resolve();
      }
    };
    const q = new Queue(callback as (item: QueueItem) => void);
    q.enqueue(new Animal('dog', 'Pluto')).catch((error: Error) => { throw error; });
    assert.strictEqual(q.pending.length, 0, `q.pending.length`);
    q.enqueue(new Animal('cat', 'Figaro')).catch((error: Error) => { throw error; });
    assert.strictEqual(q.pending.length, 1, `q.pending.length`);
    await wait(110);
    assert.strictEqual(q.pending.length, 0, `q.pending.length`);
  });