![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
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
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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.