Quellcode durchsuchen

[misc] simplify the naming around waiting for a mongo connection

Co-Authored-By: Eric Mc Sween <eric.mcsween@overleaf.com>
Co-Authored-By: Miguel Serrano <mserranom@gmail.com>
Co-Authored-By: Simon Detheridge <s@sd.ai>
Jakob Ackermann vor 6 Jahren
Ursprung
Commit
39ea30355e
2 geänderte Dateien mit 10 neuen und 5 gelöschten Zeilen
  1. 2 1
      services/chat/app.js
  2. 8 4
      services/chat/app/js/mongodb.js

+ 2 - 1
services/chat/app.js

@@ -23,7 +23,8 @@ if (!module.parent) {
       settings.internal != null ? settings.internal.chat : undefined,
       (x1) => x1.host
     ) || 'localhost'
-  mongodb.clientConnecting
+  mongodb
+    .waitForDb()
     .then(() => {
       Server.server.listen(port, host, function (err) {
         if (err) {

+ 8 - 4
services/chat/app/js/mongodb.js

@@ -1,15 +1,19 @@
 const Settings = require('settings-sharelatex')
 const { MongoClient, ObjectId } = require('mongodb')
 
-const clientConnecting = MongoClient.connect(Settings.mongo.url)
-const dbPromise = clientConnecting.then((client) => client.db())
+const clientPromise = MongoClient.connect(Settings.mongo.url)
+const dbPromise = clientPromise.then((client) => client.db())
 
 async function getCollection(name) {
   return (await dbPromise).collection(name)
 }
 
+async function waitForDb() {
+  await clientPromise
+}
+
 module.exports = {
-  clientConnecting,
   ObjectId,
-  getCollection
+  getCollection,
+  waitForDb
 }