Files
.idea
node_modules
@discordjs
abort-controller
asynckit
better-js-class
bignumber.js
combined-stream
core-util-is
cps
delayed-stream
denque
discord-anti-spam
discord.js
event-target-shim
generate-function
iconv-lite
inherits
is-property
isarray
long
lru-cache
mime-db
mime-types
mysql
lib
protocol
Connection.js
ConnectionConfig.js
Pool.js
PoolCluster.js
PoolConfig.js
PoolConnection.js
PoolNamespace.js
PoolSelector.js
Changes.md
License
Readme.md
index.js
package.json
mysql2
named-placeholders
node-fetch
node-mysql
prism-media
process-nextick-args
pseudomap
readable-stream
safe-buffer
safer-buffer
seq-queue
setimmediate
sqlstring
string_decoder
tweetnacl
underscore
util-deprecate
ws
yallist
config.json
index.js
package-lock.json
package.json
woam-antispam-bot.iml
Woam-Antispam-Bot/node_modules/mysql/lib/PoolConnection.js
2021-03-14 11:09:02 +01:00

66 lines
1.7 KiB
JavaScript

var inherits = require('util').inherits;
var Connection = require('./Connection');
var Events = require('events');
module.exports = PoolConnection;
inherits(PoolConnection, Connection);
function PoolConnection(pool, options) {
Connection.call(this, options);
this._pool = pool;
// Bind connection to pool domain
if (Events.usingDomains) {
this.domain = pool.domain;
}
// When a fatal error occurs the connection's protocol ends, which will cause
// the connection to end as well, thus we only need to watch for the end event
// and we will be notified of disconnects.
this.on('end', this._removeFromPool);
this.on('error', function (err) {
if (err.fatal) {
this._removeFromPool();
}
});
}
PoolConnection.prototype.release = function release() {
var pool = this._pool;
if (!pool || pool._closed) {
return undefined;
}
return pool.releaseConnection(this);
};
// TODO: Remove this when we are removing PoolConnection#end
PoolConnection.prototype._realEnd = Connection.prototype.end;
PoolConnection.prototype.end = function () {
console.warn(
'Calling conn.end() to release a pooled connection is ' +
'deprecated. In next version calling conn.end() will be ' +
'restored to default conn.end() behavior. Use ' +
'conn.release() instead.'
);
this.release();
};
PoolConnection.prototype.destroy = function () {
Connection.prototype.destroy.apply(this, arguments);
this._removeFromPool(this);
};
PoolConnection.prototype._removeFromPool = function _removeFromPool() {
if (!this._pool || this._pool._closed) {
return;
}
var pool = this._pool;
this._pool = null;
pool._purgeConnection(this);
};