651e40133ed41b0a3bfa5296ec674ab512dca74ac324a45d2f4108bc1d388af4f2a159033ec501db92d4ca766902deec057cbe783b4f00debeb13de1d6cab5 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # p-finally [![Build Status](https://travis-ci.org/sindresorhus/p-finally.svg?branch=master)](https://travis-ci.org/sindresorhus/p-finally)
  2. > [`Promise#finally()`](https://github.com/tc39/proposal-promise-finally) [ponyfill](https://ponyfill.com) - Invoked when the promise is settled regardless of outcome
  3. Useful for cleanup.
  4. ## Install
  5. ```
  6. $ npm install p-finally
  7. ```
  8. ## Usage
  9. ```js
  10. const pFinally = require('p-finally');
  11. const directory = createTempDirectory();
  12. (async () => {
  13. await pFinally(write(directory), () => {
  14. cleanup(directory);
  15. });
  16. });
  17. ```
  18. ## API
  19. ### pFinally(promise, onFinally?)
  20. Returns a `Promise`.
  21. #### onFinally
  22. Type: `Function`
  23. Note: Throwing or returning a rejected promise will reject `promise` with the rejection reason.
  24. ## Related
  25. - [p-try](https://github.com/sindresorhus/p-try) - `Promise.try()` ponyfill - Starts a promise chain
  26. - [More…](https://github.com/sindresorhus/promise-fun)
  27. ---
  28. <div align="center">
  29. <b>
  30. <a href="https://tidelift.com/subscription/pkg/npm-p-finally?utm_source=npm-p-finally&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
  31. </b>
  32. <br>
  33. <sub>
  34. Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
  35. </sub>
  36. </div>