Socket
Socket
Sign inDemoInstall

p-finally

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Protect your apps from supply chain attacks

Install

p-finally

`Promise#finally()` ponyfill - Invoked when the promise is settled regardless of outcome

    3.0.0latest
    GitHub
    npm

Version published
Maintainers
1
Weekly downloads
20,187,152
increased by2.96%

Weekly downloads

Package description

What is p-finally?

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.

What are p-finally's main functionalities?

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
});

Other packages similar to p-finally

Readme

Source

p-finally

Promise#finally() ponyfill - Invoked when the promise is settled regardless of outcome

Useful for cleanup.

Install

$ npm install p-finally

Usage

import pFinally from 'p-finally';

const directory = createTempDirectory();

await pFinally(write(directory), () => {
	cleanup(directory);
});

API

pFinally(promise, onFinally?)

Returns a Promise.

onFinally

Type: Function

Note: Throwing or returning a rejected promise will reject promise with the rejection reason.

  • p-try - Promise.try() ponyfill - Starts a promise chain
  • More…

Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Keywords

FAQs

Last updated on 09 Apr 2021

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc