Dispose a resource when p-using resolves.
npm install p-using> Dispose a resource when p-using resolves.
[travis-image]: https://img.shields.io/travis/ngryman/p-using.svg?style=flat
[travis-url]: https://travis-ci.org/ngryman/p-using
[codecov-image]: https://img.shields.io/codecov/c/github/ngryman/p-using.svg
[codecov-url]: https://codecov.io/github/ngryman/p-using
[size-image]: http://img.badgesize.io/https://unpkg.com/p-using@1.0.0/dist/p-using.min.js?compression=gzip
[size-url]: https://unpkg.com/p-using@1.0.0/dist/p-using.min.js
Inspired from Bluebird, p-using makes sure that the specifed dispose function is called on a resource.
``sh`
$ npm install --save p-using
`js
import using from 'p-using'
// call db.dispose method
using(db, () => { db.query('...') })
// call db.close method
using(db, () => { db.query('...') }, 'close')
// call the provided dispose function
using(db, () => { db.query('...') }, db => { db.finalize() })
`
Parameters
- resource (Object \| Promise) Resource to be disposed.callback
- Function Function to be invoked before disposal.disposeFunction` (String \| Function) Name of the method or function called for disposal.
-
Returns Promise Promise resolved when the resource has been disposed.
MIT © Nicolas Gryman