Gathering detailed insights and metrics for make-cancellable-promise
Gathering detailed insights and metrics for make-cancellable-promise
Gathering detailed insights and metrics for make-cancellable-promise
Gathering detailed insights and metrics for make-cancellable-promise
npm install make-cancellable-promise
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
28 Stars
214 Commits
2 Forks
3 Watching
3 Branches
1 Contributors
Updated on 20 Nov 2024
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
-6.3%
185,846
Compared to previous day
Last week
0.6%
1,009,223
Compared to previous week
Last month
7.3%
4,355,454
Compared to previous month
Last year
48%
42,639,407
Compared to previous year
Make any Promise cancellable.
npm install make-cancellable-promise
or yarn add make-cancellable-promise
.import makeCancellablePromise from 'make-cancellable-promise
.1const { promise, cancel } = makeCancellablePromise(myPromise);
A function that returns an object with two properties:
promise
and cancel
. promise
is a wrapped around your promise. cancel
is a function which stops .then()
and .catch()
from working on promise
, even if promise passed to makeCancellablePromise
resolves or rejects.
1const { promise, cancel } = makeCancellablePromise(myPromise);
Typically, you'd want to use makeCancellablePromise
in React components. If you call setState
on an unmounted component, React will throw an error.
Here's how you can use makeCancellablePromise
with React:
1function MyComponent() { 2 const [status, setStatus] = useState('initial'); 3 4 useEffect(() => { 5 const { promise, cancel } = makeCancellable(fetchData()); 6 7 promise.then(() => setStatus('success')).catch(() => setStatus('error')); 8 9 return () => { 10 cancel(); 11 }; 12 }, []); 13 14 const text = (() => { 15 switch (status) { 16 case 'pending': 17 return 'Fetching…'; 18 case 'success': 19 return 'Success'; 20 case 'error': 21 return 'Error!'; 22 default: 23 return 'Click to fetch'; 24 } 25 })(); 26 27 return <p>{text}</p>; 28}
The MIT License.
Wojciech Maj |
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
0 existing vulnerabilities detected
Reason
11 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 9
Reason
Found 0/29 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More