lightning-pool
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -24,4 +24,4 @@ /* lightning-pool | ||
STARTED: 1, | ||
STOPPING: 2, | ||
STOPPED: 3 | ||
CLOSING: 2, | ||
CLOSED: 3 | ||
}; | ||
@@ -232,3 +232,3 @@ | ||
Pool.prototype.start = function() { | ||
if (this._state >= PoolState.STOPPING) | ||
if (this._state >= PoolState.CLOSING) | ||
throw new Error('Closed pool can not be started again'); | ||
@@ -250,3 +250,3 @@ if (this._state === PoolState.STARTED) | ||
*/ | ||
Pool.prototype.stop = function(force, callback) { | ||
Pool.prototype.close = function(force, callback) { | ||
if (typeof force === 'function') { | ||
@@ -259,11 +259,11 @@ callback = force; | ||
return promisify.fromCallback(function(cb) { | ||
self.stop(force, cb); | ||
self.close(force, cb); | ||
}); | ||
if (this._state !== PoolState.STARTED) | ||
return callback(); | ||
self._state = PoolState.STOPPING; | ||
self._state = PoolState.CLOSING; | ||
self._requestQueue = new DoublyLinked(); | ||
self._requestsProcessing = 0; | ||
self._emitSafe('stopping'); | ||
self.once('stop', callback); | ||
self._emitSafe('closing'); | ||
self.once('close', callback); | ||
if (force) { | ||
@@ -432,16 +432,16 @@ self._acquiredResources.forEach(function(t) { | ||
const self = this; | ||
const isStopping = self._state === PoolState.STOPPING; | ||
const isClosing = self._state === PoolState.CLOSING; | ||
const now = Date.now(); | ||
var m = self._allResources.size - self.options.min; | ||
var n = self._idleResources.length - self.options.minIdle; | ||
if (isStopping || (m > 0 && n > 0)) { | ||
if (isClosing || (m > 0 && n > 0)) { | ||
self._idleResources.every(function(t) { | ||
if (isStopping || | ||
if (isClosing || | ||
t.iddleTime + self.options.idleTimeoutMillis < now) { | ||
t.destroy(); | ||
return isStopping || ((--n) && (--m)); | ||
return isClosing || ((--n) && (--m)); | ||
} | ||
}); | ||
} | ||
if (isStopping) { | ||
if (isClosing) { | ||
if (self._allResources.size) | ||
@@ -453,5 +453,5 @@ /* Check again 5 ms later */ | ||
else { | ||
self._state = PoolState.STOPPED; | ||
self._state = PoolState.CLOSED; | ||
self._requestsProcessing = 0; | ||
self._emitSafe('stop'); | ||
self._emitSafe('close'); | ||
} | ||
@@ -458,0 +458,0 @@ } |
{ | ||
"name": "lightning-pool", | ||
"description": "Fastest object pool implementation for JavaScript", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"author": "Panates Ltd.", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -80,6 +80,6 @@ # lightning-pool | ||
* Step 3 - Shutdown pool (optional) | ||
* Call stop(force, callback) when you need to shutdown the pool | ||
* Call close(force, callback) when you need to shutdown the pool | ||
*/ | ||
process.on('SIGINT', function() { | ||
pool.stop(true); | ||
pool.close(true); | ||
}); | ||
@@ -166,6 +166,6 @@ ``` | ||
* Step 3 - Shutdown pool (optional) | ||
* Call stop(force, callback) when you need to shutdown the pool | ||
* Call close(force, callback) when you need to shutdown the pool | ||
*/ | ||
process.on('SIGINT', function() { | ||
pool.stop(true); | ||
pool.close(true); | ||
}); | ||
@@ -343,3 +343,3 @@ ``` | ||
#### Pool.prototype.stop() | ||
#### Pool.prototype.close() | ||
@@ -350,3 +350,3 @@ Shuts down the `Pool` and destroys all resources. | ||
`pool.stop([force], callback)` | ||
`pool.close([force], callback)` | ||
@@ -358,3 +358,3 @@ - `force` (optional): If true, `Pool` will immediately destroy resources instead of waiting to be released (Default false) | ||
```js | ||
pool.stop(function(error) { | ||
pool.close(function(error) { | ||
if (error) | ||
@@ -368,3 +368,3 @@ return console.error(error); | ||
`pool.stop([force])` | ||
`pool.close([force])` | ||
@@ -375,3 +375,3 @@ - `force` (optional): If true, `Pool` will immediately destroy resources instead of waiting to be released (Default false) | ||
```js | ||
var promise = pool.stop(); | ||
var promise = pool.close(); | ||
promise.then(() => { | ||
@@ -456,5 +456,5 @@ console.log('Pool has been shut down') | ||
- `stopping`: Emitted when before stopping the `Pool`. | ||
- `closing`: Emitted when before closing the `Pool`. | ||
```js | ||
pool.on('stopping', function(){ | ||
pool.on('closing', function(){ | ||
//... | ||
@@ -465,5 +465,5 @@ }) | ||
- `stop`: Emitted when after stopping the `Pool`. | ||
- `close`: Emitted when after closing the `Pool`. | ||
```js | ||
pool.on('stop', function(){ | ||
pool.on('close', function(){ | ||
//... | ||
@@ -488,5 +488,5 @@ }) | ||
- STOPPING: 2, // Pool shutdown in progress | ||
- CLOSING: 2, // Pool shutdown in progress | ||
- STOPPED: 3 // Pool has been shut down | ||
- CLOSED: 3 // Pool has been shut down | ||
@@ -493,0 +493,0 @@ |
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
36299