Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
`Promise#finally()` ponyfill - Invoked when the promise is settled regardless of outcome
The p-finally npm package is designed to allow you to attach a handler that will be called when a promise is settled (either fulfilled or rejected). This is useful for running cleanup code or finalizing operations, regardless of the promise's outcome.
Attaching a finally handler to a promise
This feature allows you to execute code after a promise has been settled, regardless of whether it was fulfilled or rejected. It's particularly useful for cleanup operations.
const pFinally = require('p-finally');
const promise = new Promise((resolve, reject) => {
// Some asynchronous operation
});
pFinally(promise, () => {
// Code to run on promise settlement
});
Bluebird is a comprehensive promise library that includes a .finally() method among its wide array of features. Compared to p-finally, Bluebird offers a much broader set of promise-related utilities, but it's also larger in size, which might be an overkill for projects only needing a finally functionality.
Q is another promise library that supports a .finally() method. Similar to Bluebird, Q provides a wide range of promise manipulation capabilities. It's more feature-rich than p-finally but also larger, making p-finally a lightweight alternative if the finally functionality is the main requirement.
Promise#finally()
ponyfill - Invoked when the promise is settled regardless of outcome
Useful for cleanup.
$ npm install p-finally
import pFinally from 'p-finally';
const directory = createTempDirectory();
await pFinally(write(directory), () => {
cleanup(directory);
});
Returns a Promise
.
Type: Function
Note: Throwing or returning a rejected promise will reject promise
with the rejection reason.
FAQs
`Promise#finally()` ponyfill - Invoked when the promise is settled regardless of outcome
We found that p-finally 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.