JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 10
  • Score
    100M100P100Q50895F
  • License ISC

An AbortController that aborts after a specified timeout

Package Exports

  • abort-controller-timer
  • abort-controller-timer/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (abort-controller-timer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

README.md

An AbortController that aborts after a specified timeout

install

yarn add abort-controller-timer abort-controller
yarn-tool add abort-controller-timer abort-controller
yt add abort-controller-timer abort-controller
import AbortControllerTimer from 'abort-controller-timer';

test(`base`, (done) =>
{
    expect.assertions(8);

    let start = Date.now();

    let timeout = 100;
    let actual = new AbortControllerTimer(timeout);

    actual.on('abort', () => {
        let d = Date.now() - start;
        console.dir(d);

        expect(d).toBeGreaterThanOrEqual(100);
        expect(d).toBeLessThanOrEqual(110);
    })

    setTimeout(() => {
        expect(actual.aborted).toBeFalsy();
        expect(actual.timer).toBeTruthy()
    }, 70);

    setTimeout(() => expect(actual.aborted).toBeTruthy(), 100);
    setTimeout(() => expect(actual.aborted).toBeTruthy(), 150);
    setTimeout(() =>
    {
        expect(actual.aborted).toBeTruthy();
        done();
    }, 200);

    expect(actual).toHaveProperty('ms', timeout);

});

test(`refresh`, (done) =>
{
    expect.assertions(12);

    let start = Date.now();

    let timeout = 100;
    let actual = new AbortControllerTimer(timeout);

    actual.on('abort', () => {
        let d = Date.now() - start;
        console.dir(d);

        expect(d).toBeGreaterThanOrEqual(170);
        expect(d).toBeLessThanOrEqual(180);
    })

    setTimeout(() => {
        expect(Date.now() - start).toBeGreaterThanOrEqual(70);
        expect(actual.aborted).toBeFalsy();
        expect(actual.refresh()).toBeTruthy()
    }, 70);

    setTimeout(() => {
        expect(Date.now() - start).toBeGreaterThanOrEqual(100);
        expect(actual.aborted).toBeFalsy()
    }, 100);
    setTimeout(() => {
        expect(Date.now() - start).toBeGreaterThanOrEqual(150);
        expect(actual.aborted).toBeFalsy()
    }, 150);
    setTimeout(() =>
    {
        expect(Date.now() - start).toBeGreaterThanOrEqual(200);
        expect(actual.aborted).toBeTruthy();
        done();
    }, 200);

    expect(actual).toHaveProperty('ms', timeout);

});