timer-abort-controller
v0.0.3
Published
The repo contains a handy class for AbortController interaction
Downloads
2
Readme
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);
}
})();