Skip to content

Commit

Permalink
add README
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorrPopov committed Dec 9, 2023
2 parents 49a2213 + 252d118 commit 5567710
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-clouds-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"timer-abort-controller": patch
---

add README and rename the class
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
## Description
The repo contains a handy class for AbortController interaction
# Timer Abort Controller

## A wrapper for NodeJS AbortController class that makes interaction easier

## Installation

```bash
$ npm i timer-abort-controller
```

#### This code snippet shows how it works

```javascript
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);
}
})();
```
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class AbortControllerTimer {
export class TimerAbortController {
static async resolveInTime<T>(
promise: Promise<T>,
timeLimit = 10_000,
Expand All @@ -11,7 +11,7 @@ export class AbortControllerTimer {
timeLimit,
);

return AbortControllerTimer.resolve<T>(promise, signal, timeout);
return TimerAbortController.resolve<T>(promise, signal, timeout);
}

private static async resolve<T>(
Expand Down

0 comments on commit 5567710

Please sign in to comment.