Skip to content

Commit

Permalink
fix(connection): use queueing instead of event emitter for `createCol…
Browse files Browse the repository at this point in the history
…lection()` and other helpers to avoid event emitter warning

Fix #9778
  • Loading branch information
vkarpov15 committed Mar 31, 2021
1 parent 5382408 commit 58cad73
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/connection.js
Expand Up @@ -73,6 +73,7 @@ function Connection(base) {
} else {
this.id = base.connections.length;
}
this._queue = [];
}

/*!
Expand Down Expand Up @@ -569,9 +570,7 @@ function _wrapConnHelper(fn) {
// Re: gh-8534
immediate(() => {
if (this.readyState === STATES.connecting && this._shouldBufferCommands()) {
this.once('open', function() {
fn.apply(this, argsWithoutCb.concat([cb]));
});
this._queue.push({ fn: fn, ctx: this, args: argsWithoutCb.concat([cb]) });
} else if (this.readyState === STATES.disconnected && this.db == null) {
cb(disconnectedError);
} else {
Expand Down Expand Up @@ -631,6 +630,11 @@ Connection.prototype.error = function(err, callback) {
Connection.prototype.onOpen = function() {
this.readyState = STATES.connected;

for (const d of this._queue) {
d.fn.apply(d.ctx, d.args);
}
this._queue = [];

// avoid having the collection subscribe to our event emitter
// to prevent 0.3 warning
for (const i in this.collections) {
Expand Down

0 comments on commit 58cad73

Please sign in to comment.