generic-pool
Advanced tools
Comparing version 3.1.8 to 3.2.0
# Change Log | ||
## [3.2.0] - October 15 2017 | ||
- add `isBorrowedResource` method to check if objects are currently on loan from pool (@C-h-e-r-r-y) | ||
## [3.1.8] - September 14 2017 | ||
@@ -161,3 +164,4 @@ - fix undefined and annoying `autostart=false` behaviour (@sushantdhiman) | ||
======= | ||
[unreleased]: https://github.com/coopernurse/node-pool/compare/v3.1.8...HEAD | ||
[unreleased]: https://github.com/coopernurse/node-pool/compare/v3.2.0...HEAD | ||
[3.2.0]: https://github.com/coopernurse/node-pool/compare/v3.1.8...v3.2.0 | ||
[3.1.8]: https://github.com/coopernurse/node-pool/compare/v3.1.7...v3.1.8 | ||
@@ -164,0 +168,0 @@ [3.1.7]: https://github.com/coopernurse/node-pool/compare/v3.1.6...v3.1.7 |
@@ -415,2 +415,15 @@ 'use strict' | ||
/** | ||
* Check if resource is currently on loan from the pool | ||
* | ||
* @param {Function} resource | ||
* Resource for checking. | ||
* | ||
* @returns {Boolean} | ||
* True if resource belongs to this pool and false otherwise | ||
*/ | ||
isBorrowedResource (resource) { | ||
return this._resourceLoans.get(resource) !== undefined | ||
} | ||
/** | ||
@@ -417,0 +430,0 @@ * Return the resource to the pool when it is no longer required. |
{ | ||
"name": "generic-pool", | ||
"description": "Generic resource pooling for Node.JS", | ||
"version": "3.1.8", | ||
"version": "3.2.0", | ||
"author": "James Cooper <james@bitmechanic.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -188,2 +188,16 @@ [![build status](https://secure.travis-ci.org/coopernurse/node-pool.png)](http://travis-ci.org/coopernurse/node-pool) | ||
### pool.isBorrowedResource | ||
```js | ||
pool.isBorrowedResource(resource) | ||
``` | ||
This function is for when you need to check if a resource has been acquired from the pool and not yet released/destroyed. | ||
`isBorrowedResource` takes one required argument: | ||
- `resource`: any object which you need to test | ||
and returns true (primitive, not Promise) if resource is currently borrowed from the pool, false otherwise. | ||
### pool.destroy | ||
@@ -190,0 +204,0 @@ |
@@ -638,2 +638,49 @@ 'use strict' | ||
tap.test('isBorrowedResource should return true for borrowed resource', function (t) { | ||
const pool = createPool({ | ||
create: function () { | ||
return Promise.resolve({ id: 'validId' }) | ||
}, | ||
validate: function (resource) { | ||
return Promise.resolve(true) | ||
}, | ||
destroy: function (client) {}, | ||
max: 1 | ||
}) | ||
pool.acquire() | ||
.then(function (obj) { | ||
t.equal(pool.isBorrowedResource(obj), true) | ||
pool.release(obj) | ||
utils.stopPool(pool) | ||
t.end() | ||
}) | ||
.catch(t.threw) | ||
}) | ||
tap.test('isBorrowedResource should return false for released resource', function (t) { | ||
const pool = createPool({ | ||
create: function () { | ||
return Promise.resolve({ id: 'validId' }) | ||
}, | ||
validate: function (resource) { | ||
return Promise.resolve(true) | ||
}, | ||
destroy: function (client) {}, | ||
max: 1 | ||
}) | ||
pool.acquire() | ||
.then(function (obj) { | ||
pool.release(obj) | ||
return obj | ||
}) | ||
.then(function (obj) { | ||
t.equal(pool.isBorrowedResource(obj), false) | ||
utils.stopPool(pool) | ||
t.end() | ||
}) | ||
.catch(t.threw) | ||
}) | ||
tap.test('destroy should redispense', function (t) { | ||
@@ -640,0 +687,0 @@ const pool = createPool({ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
91194
2167
386