Comparing version 1.1.9 to 1.2.0
@@ -24,2 +24,3 @@ /* | ||
const mod_utils = require('./utils'); | ||
const mod_vasync = require('vasync'); | ||
@@ -56,2 +57,3 @@ const Pool = mod_pool.ConnectionPool; | ||
this.log = options.log; | ||
this.cba_stopped = false; | ||
@@ -95,2 +97,5 @@ mod_assert.number(options.spares, 'options.spares'); | ||
var self = this; | ||
if (this.cba_stopped) { | ||
throw (new Error('Cannot add a pool to a stopped agent')); | ||
} | ||
mod_assert.string(host, 'hostname'); | ||
@@ -162,5 +167,41 @@ var poolOpts = { | ||
} | ||
this.log.debug({ host: host }, 'CueBallAgent creating new pool'); | ||
this.pools[host] = new Pool(poolOpts); | ||
}; | ||
CueBallAgent.prototype.stop = function (cb) { | ||
var self = this; | ||
if (this.cba_stopped) { | ||
throw (new Error('Cannot stop a CueBallAgent that has ' + | ||
'already stopped')); | ||
} | ||
this.cba_stopped = true; | ||
this.log.debug('CueBallAgent stopping all pools'); | ||
mod_vasync.forEachParallel({ | ||
inputs: Object.keys(this.pools), | ||
func: stopPool | ||
}, function (err) { | ||
self.log.info('CueBallAgent has stopped all pools'); | ||
if (cb) { | ||
setImmediate(function () { | ||
cb(err); | ||
}); | ||
} | ||
}); | ||
function stopPool(host, pcb) { | ||
var pool = self.pools[host]; | ||
delete (self.pools[host]); | ||
if (pool.isInState('stopped')) { | ||
pcb(); | ||
} else { | ||
pool.on('stateChanged', function (st) { | ||
if (st === 'stopped') { | ||
pcb(); | ||
} | ||
}); | ||
pool.stop(); | ||
} | ||
} | ||
}; | ||
/* | ||
@@ -175,2 +216,6 @@ * Sets up a duplex stream to be used for the given HTTP request. | ||
CueBallAgent.prototype.addRequest = function (req, optionsOrHost, port) { | ||
if (this.cba_stopped) { | ||
throw (new Error('CueBallAgent is stopped and cannot handle ' + | ||
'new requests')); | ||
} | ||
var options; | ||
@@ -177,0 +222,0 @@ mod_assert.object(req, 'req'); |
{ | ||
"name": "cueball", | ||
"version": "1.1.9", | ||
"version": "1.2.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -87,2 +87,15 @@ cueball | ||
### HttpAgent#stop([cb]) | ||
Stops the pools managed by this agent, calling `cb` (if given) once all have | ||
stopped. | ||
Once an Agent has been stopped, it can no longer accept any new requests, and | ||
will throw an Error if asked to do so. Calling `stop()` more than once is | ||
also an error and will throw. | ||
Parameters | ||
- `cb` -- optional Function (err) | ||
## Pool | ||
@@ -89,0 +102,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
155697
3768
751