Skip to content

Commit

Permalink
chore: improve readme (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnakamashi authored Sep 21, 2024
1 parent dad0dcb commit 8105577
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# abortable-promise

Promises that can be aborted using AbortController

```typescript
const abortController = new AbortController()
const promise = new AbortablePromise(
(resolve, reject) => {
setTimeout(() => {
resolve('success')
}, 200)
setTimeout(() => {
reject('error')
}, 300)
},
{ signal: abortController.signal },
)

setTimeout(() => {
abortController.abort('aborted by the user')
}, 100)

promise
.then((result) => {
console.log(result)
})
.catch((error) => {
console.log(error)
})
```

It should log `aborted by the user`

0 comments on commit 8105577

Please sign in to comment.