Socket
Socket
Sign inDemoInstall

p-finally

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 2.0.0

24

index.js
'use strict';
module.exports = (promise, onFinally) => {
onFinally = onFinally || (() => {});
return promise.then(
val => new Promise(resolve => {
resolve(onFinally());
}).then(() => val),
err => new Promise(resolve => {
resolve(onFinally());
}).then(() => {
throw err;
})
);
module.exports = async (
promise,
onFinally = (() => {})
) => {
try {
const value = await promise;
await onFinally();
return value;
} catch (error) {
await onFinally();
throw error;
}
};
{
"name": "p-finally",
"version": "1.0.0",
"description": "`Promise#finally()` ponyfill - Invoked when the promise is settled regardless of outcome",
"license": "MIT",
"repository": "sindresorhus/p-finally",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"promise",
"finally",
"handler",
"function",
"async",
"await",
"promises",
"settled",
"ponyfill",
"polyfill",
"shim",
"bluebird"
],
"devDependencies": {
"ava": "*",
"xo": "*"
},
"xo": {
"esnext": true
}
"name": "p-finally",
"version": "2.0.0",
"description": "`Promise#finally()` ponyfill - Invoked when the promise is settled regardless of outcome",
"license": "MIT",
"repository": "sindresorhus/p-finally",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"promise",
"finally",
"handler",
"function",
"async",
"await",
"promises",
"settled",
"ponyfill",
"polyfill",
"shim",
"bluebird"
],
"devDependencies": {
"ava": "^1.4.1",
"xo": "^0.24.0"
}
}

@@ -11,3 +11,3 @@ # p-finally [![Build Status](https://travis-ci.org/sindresorhus/p-finally.svg?branch=master)](https://travis-ci.org/sindresorhus/p-finally)

```
$ npm install --save p-finally
$ npm install p-finally
```

@@ -21,5 +21,9 @@

const dir = createTempDir();
const directory = createTempDir();
pFinally(write(dir), () => cleanup(dir));
(async () => {
await pFinally(write(directory), () => {
cleanup(directory);
});
});
```

@@ -43,8 +47,3 @@

- [p-try](https://github.com/sindresorhus/p-try) - `Promise#try()` ponyfill - Starts a promise chain
- [p-try](https://github.com/sindresorhus/p-try) - `Promise.try()` ponyfill - Starts a promise chain
- [More…](https://github.com/sindresorhus/promise-fun)
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)

Sorry, the diff of this file is not supported yet

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