Skip to content

Commit

Permalink
Merge pull request #22 from sebastiendavid/is-canceled
Browse files Browse the repository at this point in the history
add isCanceled method
  • Loading branch information
sebdvd authored Apr 28, 2020
2 parents 1987549 + fad1157 commit c592c48
Show file tree
Hide file tree
Showing 10 changed files with 503 additions and 6,179 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ jobs:
cypress-run:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Cypress run
uses: cypress-io/github-action@v1
- uses: actions/checkout@v2
- uses: cypress-io/github-action@v1
with:
browser: chrome
headless: true
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## 3.0.0 (2020-04-07)
## [3.1.0](https://github.com/alkemics/CancelablePromise/releases/tag/v3.1.0) (2020-04-28)

- upgrade dev dependencies
- add `isCanceled` method to cancelable promises

## [3.0.0](https://github.com/alkemics/CancelablePromise/releases/tag/v3.0.0) (2020-04-07)

- Complete rewrite of `CancelablePromise`.
Now promises returned from `Promise` API such as `then` or `catch` can cancel the root promise and all promises created from this root promise:
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ FYI, you can cancel a fetch request with AbortController & AbortSignal.
- [API](#api)
- [cancelable](#cancelable)
- [CancelablePromise](#cancelablepromise)
- [CancelablePromise.cancel](#cancelablepromisecancel)
- [CancelablePromise.isCanceled](#cancelablepromiseiscanceled)
- [Static methods](#static-methods)
- [Scripts](#scripts)
- [Build](#build)
Expand Down Expand Up @@ -112,6 +114,24 @@ new CancelablePromise((resolve, reject) => {
});
```

### CancelablePromise.cancel

```javascript
/**
* @returns {void}
*/
cancelablePromise.cancel();
```

### CancelablePromise.isCanceled

```javascript
/**
* @returns {boolean}
*/
cancelablePromise.isCanceled();
```

### Static methods

Same as Promise static methods.
Expand Down
4 changes: 4 additions & 0 deletions cypress/integration/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ describe('cancelable promise', () => {
const promise = new CancelablePromise((resolve) => {
resolve(42);
}).then(stub);
expect(promise.isCanceled()).to.be.false;
promise.cancel();
expect(promise.isCanceled()).to.be.true;
cy.wait(1).then(() => {
expect(stub).not.to.be.called;
});
Expand All @@ -45,7 +47,9 @@ describe('cancelable promise', () => {
const promise = new CancelablePromise((resolve, reject) => {
reject(42);
}).catch(stub);
expect(promise.isCanceled()).to.be.false;
promise.cancel();
expect(promise.isCanceled()).to.be.true;
cy.wait(1).then(() => {
expect(stub).not.to.be.called;
});
Expand Down
Loading

0 comments on commit c592c48

Please sign in to comment.