Skip to content
Dispose a resource when p-using promise resolves.
Branch: master
Clone or download
Pull request Compare This branch is 2 commits ahead of ngryman:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.babelrc
.editorconfig
.eslintrc
.gitattributes
.gitignore
.nycrc
.travis.yml
index.js
license
package-lock.json
package.json
readme.md
rollup.config.js
test.js

readme.md

p-using travis codecov size

Dispose a resource when p-using resolves.

Inspired from Bluebird, p-using makes sure that the specified dispose function is called on a resource.

Installation

$ npm install --save p-using

Usage

import using from 'p-using'

// call `db.dispose` method
using(db, db => { db.query('...') })

// call `db.close` method
using(db, db => { db.query('...') }, 'close')

// call the provided dispose function
using(db, db => { db.query('...') }, db => { db.finalize() })

// accept a resource promise
using(createDb(), db => { db.query('...') })

API

using

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.

License

MIT © Nicolas Gryman

You can’t perform that action at this time.