Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/p-finally
`Promise#finally()` ponyfill - Invoked when the promise is settled regardless of outcome
https://github.com/sindresorhus/p-finally
Last synced: about 2 months ago
JSON representation
`Promise#finally()` ponyfill - Invoked when the promise is settled regardless of outcome
- Host: GitHub
- URL: https://github.com/sindresorhus/p-finally
- Owner: sindresorhus
- License: mit
- Archived: true
- Created: 2016-10-21T05:50:16.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2021-04-09T05:45:17.000Z (about 3 years ago)
- Last Synced: 2024-04-18T07:12:59.600Z (2 months ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 45
- Watchers: 7
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
- Security: .github/security.md
Lists
- awesome-promises - p-finally - `Promise#finally()` ponyfill - Invoked when the promise is settled regardless of outcome (Convenience Utilities / sindresorhus's many Promise utilities ([see notes](https://github.com/sindresorhus/promise-fun)))
README
Deprecated as it's now available in all modern browsers and Node.js versions.
---
# p-finally
> [`Promise#finally()`](https://github.com/tc39/proposal-promise-finally) [ponyfill](https://ponyfill.com) - Invoked when the promise is settled regardless of outcome
Useful for cleanup.
## Install
```
$ npm install p-finally
```## Usage
```js
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.
## Related
- [p-try](https://github.com/sindresorhus/p-try) - `Promise.try()` ponyfill - Starts a promise chain
- [More…](https://github.com/sindresorhus/promise-fun)