generic-pool
Advanced tools
Comparing version 2.5.2 to 2.5.3
# Change Log | ||
## [2.5.3] - January 20 2017 | ||
- fixes #141 - destroyAllNow can now fire a callback when all resources are destroyed (@llafuente) | ||
## [2.5.2] - January 20 2017 | ||
@@ -131,3 +134,4 @@ - linting... | ||
[unreleased]: https://github.com/coopernurse/node-pool/compare/v2.5.2...HEAD | ||
[unreleased]: https://github.com/coopernurse/node-pool/compare/v2.5.3...HEAD | ||
[2.5.3]: https://github.com/coopernurse/node-pool/compare/v2.5.2...v2.5.3 | ||
[2.5.2]: https://github.com/coopernurse/node-pool/compare/v2.5.1...v2.5.2 | ||
@@ -134,0 +138,0 @@ [2.5.1]: https://github.com/coopernurse/node-pool/compare/v2.5.0...v2.5.1 |
@@ -182,4 +182,6 @@ /** | ||
* The acquired item to be destoyed. | ||
* @param {Function} callback | ||
* Optional. Callback invoked after client is destroyed | ||
*/ | ||
Pool.prototype.destroy = function destroy (obj) { | ||
Pool.prototype.destroy = function destroy (obj, cb) { | ||
this._count -= 1 | ||
@@ -195,4 +197,9 @@ if (this._count < 0) this._count = 0 | ||
this._factory.destroy(obj) | ||
this._factory.destroy(obj, cb) | ||
// keep compatibily with old interface | ||
if (this._factory.destroy.length === 1 && cb && typeof cb === 'function') { | ||
cb() | ||
} | ||
this._ensureMinimum() | ||
@@ -535,12 +542,19 @@ } | ||
this._availableObjects = [] | ||
var todo = willDie.length | ||
var done = 0 | ||
var obj = willDie.shift() | ||
this._removeIdleScheduled = false | ||
clearTimeout(this._removeIdleTimer) | ||
while (obj !== null && obj !== undefined) { | ||
this.destroy(obj.obj) | ||
this.destroy(obj.obj, function () { | ||
++done | ||
if (done === todo && callback) { | ||
invoke(callback) | ||
return | ||
} | ||
}) | ||
obj = willDie.shift() | ||
} | ||
this._removeIdleScheduled = false | ||
clearTimeout(this._removeIdleTimer) | ||
if (callback) { | ||
invoke(callback) | ||
} | ||
} | ||
@@ -547,0 +561,0 @@ |
{ | ||
"name": "generic-pool", | ||
"description": "Generic resource pooling for Node.JS", | ||
"version": "2.5.2", | ||
"version": "2.5.3", | ||
"author": "James Cooper <james@bitmechanic.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -821,1 +821,82 @@ var tap = require('tap') | ||
}) | ||
tap.test('async destroy', function (t) { | ||
var created = 0 | ||
var destroyed = 0 | ||
var count = 5 | ||
var acquired = 0 | ||
var pool = Pool({ | ||
name: 'test4', | ||
create: function (callback) { callback(null, {id: ++created}) }, | ||
destroy: function (client, cb) { | ||
setTimeout(function () { | ||
destroyed += 1 | ||
cb() | ||
}, 250) | ||
}, | ||
max: 2, | ||
idletimeoutMillis: 300000 | ||
}) | ||
for (var i = 0; i < count; i++) { | ||
pool.acquire(function (err, client) { | ||
t.error(err) | ||
acquired += 1 | ||
t.equal(typeof client.id, 'number') | ||
setTimeout(function () { pool.release(client) }, 250) | ||
}) | ||
} | ||
t.notEqual(count, acquired) | ||
pool.drain(function () { | ||
var toDestroy = pool.availableObjectsCount() | ||
t.equal(count, acquired) | ||
// short circuit the absurdly long timeouts above. | ||
pool.destroyAllNow(function () { | ||
t.equal(toDestroy, destroyed) | ||
t.end() | ||
}) | ||
t.equal(destroyed, 0) | ||
}) | ||
}) | ||
tap.test('async destroy - no breaking change', function (t) { | ||
var created = 0 | ||
var destroyed = 0 | ||
var max = 2 | ||
var count = 5 | ||
var acquired = 0 | ||
var pool = Pool({ | ||
name: 'test4', | ||
create: function (callback) { callback(null, {id: ++created}) }, | ||
destroy: function (client) { | ||
destroyed += 1 | ||
}, | ||
max: max, | ||
idletimeoutMillis: 300000 | ||
}) | ||
for (var i = 0; i < count; i++) { | ||
pool.acquire(function (err, client) { | ||
t.error(err) | ||
acquired += 1 | ||
t.equal(typeof client.id, 'number') | ||
setTimeout(function () { pool.release(client) }, 250) | ||
}) | ||
} | ||
t.notEqual(count, acquired) | ||
pool.drain(function () { | ||
var toDestroy = pool.availableObjectsCount() | ||
t.equal(count, acquired) | ||
// short circuit the absurdly long timeouts above. | ||
pool.destroyAllNow(function () { | ||
t.equal(toDestroy, destroyed) | ||
t.end() | ||
}) | ||
t.equal(toDestroy, destroyed) | ||
}) | ||
}) |
@@ -1,2 +0,1 @@ | ||
var assert = require('assert') | ||
var tap = require('tap') | ||
@@ -40,8 +39,8 @@ | ||
// check we haven't already borrowed this before: | ||
assert.equal(borrowedObjects.indexOf(obj), -1, 'acquire returned an object is currently acquired') | ||
t.equal(borrowedObjects.indexOf(obj), -1, 'acquire returned an object is currently acquired') | ||
borrowedObjects.push(obj) | ||
// console.log( "Acquire " + num + " - object id:", obj.id ) | ||
assert.ifError(err) | ||
assert.ok(create_count <= 3) | ||
t.error(err) | ||
t.ok(create_count <= 3) | ||
@@ -48,0 +47,0 @@ setTimeout(function () { |
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
65123
1450