Skip to content

Commit 58cad73

Browse files
committedMar 31, 2021
fix(connection): use queueing instead of event emitter for createCollection() and other helpers to avoid event emitter warning
Fix #9778
1 parent 5382408 commit 58cad73

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed
 

‎lib/connection.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function Connection(base) {
7373
} else {
7474
this.id = base.connections.length;
7575
}
76+
this._queue = [];
7677
}
7778

7879
/*!
@@ -569,9 +570,7 @@ function _wrapConnHelper(fn) {
569570
// Re: gh-8534
570571
immediate(() => {
571572
if (this.readyState === STATES.connecting && this._shouldBufferCommands()) {
572-
this.once('open', function() {
573-
fn.apply(this, argsWithoutCb.concat([cb]));
574-
});
573+
this._queue.push({ fn: fn, ctx: this, args: argsWithoutCb.concat([cb]) });
575574
} else if (this.readyState === STATES.disconnected && this.db == null) {
576575
cb(disconnectedError);
577576
} else {
@@ -631,6 +630,11 @@ Connection.prototype.error = function(err, callback) {
631630
Connection.prototype.onOpen = function() {
632631
this.readyState = STATES.connected;
633632

633+
for (const d of this._queue) {
634+
d.fn.apply(d.ctx, d.args);
635+
}
636+
this._queue = [];
637+
634638
// avoid having the collection subscribe to our event emitter
635639
// to prevent 0.3 warning
636640
for (const i in this.collections) {

0 commit comments

Comments
 (0)
Please sign in to comment.