Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Wrap promise function into cancelable promise function
Sometimes you may need to create cancelable promise for situation like to avoid isMounted antipattern in React. pcancel
provides simple utility for creating cancelable promises. Highly inspired from this comment.
$ npm install --save pcancel
import pcancel from 'pcancel';
const delayC = pcancel(delay);
const p = delayC(4000)
.promise
.then(() => console.log('Yey!'))
.catch((err) => console.error(err));
p.cancel(); // Error: Promise has canceled
function delay(time) {
return new Promise((resolve) => setTimeout(() => resolve(), time));
}
fn
Function - Promise-returning function that will be cancelable.options
Object (optional)
noReject
Boolean - Whether to reject when canceling. If this option is true
, the promise will be resolved with the value passed through to cancel()
method on the promise.Returns a wrapped function that returns object includes Promise
instance and cancel()
function.
You can also specify error or value through cancel()
method, the specified value will be returned instead of value of the promise:
p.cancel(new Error('Foo')); // Error: Foo
Note: cancel()
rejects the promise immediately when it called.
FAQs
Wrap promise function into cancelable promise function
The npm package pcancel receives a total of 4 weekly downloads. As such, pcancel popularity was classified as not popular.
We found that pcancel demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.