You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
949 B

4 years ago
  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 --save p-finally
  7. ```
  8. ## Usage
  9. ```js
  10. const pFinally = require('p-finally');
  11. const dir = createTempDir();
  12. pFinally(write(dir), () => cleanup(dir));
  13. ```
  14. ## API
  15. ### pFinally(promise, [onFinally])
  16. Returns a `Promise`.
  17. #### onFinally
  18. Type: `Function`
  19. Note: Throwing or returning a rejected promise will reject `promise` with the rejection reason.
  20. ## Related
  21. - [p-try](https://github.com/sindresorhus/p-try) - `Promise#try()` ponyfill - Starts a promise chain
  22. - [More…](https://github.com/sindresorhus/promise-fun)
  23. ## License
  24. MIT © [Sindre Sorhus](https://sindresorhus.com)