timer-abort-controller
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

Timer Abort Controller

A wrapper for NodeJS AbortController class that makes interaction easier

Installation

$ npm i timer-abort-controller

This code snippet shows how it works

import { TimerAbortController } from 'timer-abort-controller';

const timeToWait = 1000;
const timeToResolve = 2000;

(async function() {
    const p = new Promise<string>((res) => {
        setTimeout(() => {
            res(`promise resolved after ${timeToResolve} milliseconds`);
        }, timeToResolve);
    });
    
    try {
        const result = await TimerAbortController.resolveInTime<string>(p, timeToWait);

        console.log(result);
    } catch (error) {
        console.log(`promise aborted after ${timeToWait} milliseconds`);
        console.log(error);
    }
})();

Readme

Keywords

none

Package Sidebar

Install

npm i timer-abort-controller

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

19 kB

Total Files

8

Last publish

Collaborators

  • ivpoov