Make pool.close() the primary release method in the code, not just in the documentation
This commit is contained in:
parent
84f796af71
commit
7c30aaf041
26
lib/pool.js
26
lib/pool.js
|
@ -22,7 +22,7 @@
|
|||
var connection = require('./connection.js');
|
||||
var nodbUtil = require('./util.js');
|
||||
var getConnectionPromisified;
|
||||
var terminatePromisified;
|
||||
var closePromisified;
|
||||
|
||||
// completeConnectionRequest does the actual work of getting a connection from a
|
||||
// pool when queuing is enabled. It's abstracted out so it can be called from
|
||||
|
@ -206,24 +206,24 @@ function getConnection(getConnectionCb) {
|
|||
|
||||
getConnectionPromisified = nodbUtil.promisify(getConnection);
|
||||
|
||||
function terminate(terminateCb) {
|
||||
function close(closeCb) {
|
||||
var self = this;
|
||||
|
||||
nodbUtil.assert(arguments.length === 1, 'NJS-009');
|
||||
nodbUtil.assert(typeof terminateCb === 'function', 'NJS-006', 1);
|
||||
nodbUtil.assert(typeof closeCb === 'function', 'NJS-006', 1);
|
||||
|
||||
self._terminate(function(err) {
|
||||
self._close(function(err) {
|
||||
if (!err) {
|
||||
self._isValid = false;
|
||||
|
||||
self.emit('_after_close', self);
|
||||
}
|
||||
|
||||
terminateCb(err);
|
||||
closeCb(err);
|
||||
});
|
||||
}
|
||||
|
||||
terminatePromisified = nodbUtil.promisify(terminate);
|
||||
closePromisified = nodbUtil.promisify(close);
|
||||
|
||||
// logStats is used to add a hidden method (_logStats) to each pool instance. This
|
||||
// provides an easy way to log out the statistics related information that's collected
|
||||
|
@ -323,7 +323,7 @@ function extend(pool, poolAttrs, poolAlias, oracledb) {
|
|||
throw new Error(nodbUtil.getErrorMessage('NJS-014', 'queueTimeout'));
|
||||
}
|
||||
},
|
||||
_isValid: { // used to ensure operations are not done after terminate
|
||||
_isValid: { // used to ensure operations are not done after close
|
||||
value: true,
|
||||
writable: true
|
||||
},
|
||||
|
@ -408,16 +408,16 @@ function extend(pool, poolAttrs, poolAlias, oracledb) {
|
|||
enumerable: true,
|
||||
writable: true
|
||||
},
|
||||
_terminate: {
|
||||
value: pool.terminate
|
||||
_close: {
|
||||
value: pool.close
|
||||
},
|
||||
terminate: {
|
||||
value: terminatePromisified,
|
||||
close: {
|
||||
value: closePromisified,
|
||||
enumerable: true,
|
||||
writable: true
|
||||
},
|
||||
close: { // alias for terminate
|
||||
value: terminatePromisified,
|
||||
terminate: { // alias for close
|
||||
value: closePromisified,
|
||||
enumerable: true,
|
||||
writable: true
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ void njsPool::Init(Handle<Object> target)
|
|||
temp->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
temp->SetClassName(Nan::New<v8::String>("Pool").ToLocalChecked());
|
||||
|
||||
Nan::SetPrototypeMethod(temp, "terminate", Terminate);
|
||||
Nan::SetPrototypeMethod(temp, "close", Close);
|
||||
Nan::SetPrototypeMethod(temp, "getConnection", GetConnection);
|
||||
|
||||
Nan::SetAccessor(temp->InstanceTemplate(),
|
||||
|
@ -416,15 +416,15 @@ void njsPool::Async_AfterGetConnection(njsBaton *baton, Local<Value> argv[])
|
|||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// njsPool::Terminate()
|
||||
// Terminate the pool. The reference to the DPI handle is transferred to the
|
||||
// njsPool::Close()
|
||||
// Close the pool. The reference to the DPI handle is transferred to the
|
||||
// baton so that it will cleared automatically upon success and so that the
|
||||
// pool is marked as invalid immediately.
|
||||
//
|
||||
// PARAMETERS
|
||||
// - JS callback which will receive (error)
|
||||
//-----------------------------------------------------------------------------
|
||||
NAN_METHOD(njsPool::Terminate)
|
||||
NAN_METHOD(njsPool::Close)
|
||||
{
|
||||
njsBaton *baton;
|
||||
njsPool *pool;
|
||||
|
@ -437,17 +437,17 @@ NAN_METHOD(njsPool::Terminate)
|
|||
return;
|
||||
baton->dpiPoolHandle = pool->dpiPoolHandle;
|
||||
pool->dpiPoolHandle = NULL;
|
||||
baton->QueueWork("Terminate", Async_Terminate, NULL, 1);
|
||||
baton->QueueWork("Close", Async_Close, NULL, 1);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// njsPool::Async_Terminate()
|
||||
// Worker function for njsPool::Terminate() method. If the attempt to
|
||||
// terminate the pool fails, the reference to the DPI handle is transferred
|
||||
// back from the baton to the pool.
|
||||
// njsPool::Async_Close()
|
||||
// Worker function for njsPool::Close() method. If the attempt to
|
||||
// close the pool fails, the reference to the DPI handle is transferred back
|
||||
// from the baton to the pool.
|
||||
//-----------------------------------------------------------------------------
|
||||
void njsPool::Async_Terminate(njsBaton *baton)
|
||||
void njsPool::Async_Close(njsBaton *baton)
|
||||
{
|
||||
if (dpiPool_close(baton->dpiPoolHandle, DPI_MODE_POOL_CLOSE_DEFAULT) < 0) {
|
||||
njsPool *pool = (njsPool*) baton->callingObj;
|
||||
|
|
|
@ -81,9 +81,9 @@ private:
|
|||
static void Async_GetConnection(njsBaton *baton);
|
||||
static void Async_AfterGetConnection(njsBaton *baton, Local<Value> argv[]);
|
||||
|
||||
// Terminate Methods
|
||||
static NAN_METHOD(Terminate);
|
||||
static void Async_Terminate(njsBaton *baton);
|
||||
// Close Methods
|
||||
static NAN_METHOD(Close);
|
||||
static void Async_Close(njsBaton *baton);
|
||||
|
||||
// Define Getter Accessors to properties
|
||||
static NAN_GETTER(GetPoolMax);
|
||||
|
|
Loading…
Reference in New Issue