From 39ea30355e706cfede9d5be97e30d4b474c797db Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Mon, 24 Aug 2020 17:06:30 +0100 Subject: [PATCH] [misc] simplify the naming around waiting for a mongo connection Co-Authored-By: Eric Mc Sween Co-Authored-By: Miguel Serrano Co-Authored-By: Simon Detheridge --- services/chat/app.js | 3 ++- services/chat/app/js/mongodb.js | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/services/chat/app.js b/services/chat/app.js index b133723f08..591e78344b 100644 --- a/services/chat/app.js +++ b/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) { diff --git a/services/chat/app/js/mongodb.js b/services/chat/app/js/mongodb.js index 245362a2a2..5b0168bda8 100644 --- a/services/chat/app/js/mongodb.js +++ b/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) } -module.exports = { - clientConnecting, - ObjectId, - getCollection +async function waitForDb() { + await clientPromise +} + +module.exports = { + ObjectId, + getCollection, + waitForDb }