Installations
npm install @byungi/p-cancel
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>= 8
Node Version
13.3.0
NPM Version
lerna/3.20.1/node@v13.3.0+x64 (win32)
Score
68.1
Supply Chain
79.9
Quality
75.1
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
skt-t1-byungi
Download Statistics
Total Downloads
6,274
Last Day
5
Last Week
9
Last Month
48
Last Year
842
GitHub Statistics
3 Stars
101 Commits
1 Forks
3 Watchers
2 Branches
1 Contributors
Updated on Nov 21, 2021
Bundle Size
1.66 kB
Minified
712.00 B
Minified + Gzipped
Package Meta Information
Latest Version
0.2.1
Package Id
@byungi/p-cancel@0.2.1
Unpacked Size
5.48 kB
Size
1.98 kB
File Count
4
NPM Version
lerna/3.20.1/node@v13.3.0+x64 (win32)
Node Version
13.3.0
Total Downloads
Cumulative downloads
Total Downloads
6,274
Last Day
150%
5
Compared to previous day
Last Week
-60.9%
9
Compared to previous week
Last Month
20%
48
Compared to previous month
Last Year
-57.5%
842
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
@byungi/p-cancel
A cancelable promise.
Example
1import PCancel, {CancelError} from '@byungi/p-cancel' 2 3const requestPromise = new PCancel((resolve, reject, onCancel) => { 4 var xhr = new XMLHttpRequest(); 5 xhr.on('load', resolve); 6 xhr.on('error', reject); 7 xhr.open('GET', 'http://delay/500ms/call', true); 8 xhr.send(null); 9 10 onCancel(()=> xhr.abort()) 11}) 12 13console.log(requestPromise.isCanceled) // => false 14 15setTimeout(()=> { 16 requestPromise.cancel() // => After 100ms, xhr is aborted. 17}, 100) 18 19requestPromise.catch(err => { 20 console.log(err.isCanceled) // => true 21 console.log(err instanceof CancelError) // => true 22 console.log(requestPromise.isCanceled) // => true 23})
API
new PCancel(executor)
PCancel
is a promise implementation. Same as promise creation except for onCancel
. onCancel
receives a function to operate on cancel()
.
1const promise = new PCancel((resolve, reject, onCancel) => {
2 const timerId = setTimeout(lazyJob, 1000)
3 onCancel(()=> clearTimeout(timerId))
4})
promise.cancel([reason])
Execute the cancel operation added with onCancel
and throw a CancelError
.
promise.isCanceled
Returns whether the promise is canceled.
promise.pipe(onFulfilled, onRejected)
Similar to then
but can propagate cancel
to the upper promise.
1const handleWithRequestPromise = requestPromise.pipe(response => { 2 handleResponse(response) 3}) 4 5handleWithRequestPromise.cancel() // => xhr is aborted
License
MIT

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
2.6
/10
Last Scanned on 2025-02-10
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