File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -830,17 +830,18 @@ Connection.prototype._waitForConnect = async function _waitForConnect(noTimeout)
830830 let timedOut = false ;
831831 // The element that this function pushes onto `_queue`, stored to make it easy to remove later
832832 const queueElement = { } ;
833+
834+ // Mongoose executes all elements in `_queue` when initial connection succeeds in `onOpen()`.
835+ const waitForConnectPromise = new Promise ( resolve => {
836+ queueElement . fn = resolve ;
837+ this . _queue . push ( queueElement ) ;
838+ } ) ;
839+
833840 if ( noTimeout ) {
834- await new Promise ( resolve => {
835- queueElement . fn = resolve ;
836- this . _queue . push ( queueElement ) ;
837- } ) ;
841+ await waitForConnectPromise ;
838842 } else {
839843 await Promise . race ( [
840- new Promise ( resolve => {
841- queueElement . fn = resolve ;
842- this . _queue . push ( queueElement ) ;
843- } ) ,
844+ waitForConnectPromise ,
844845 new Promise ( resolve => {
845846 timeout = setTimeout (
846847 ( ) => {
You can’t perform that action at this time.
0 commit comments