overleaf/services/chat/test/acceptance/js/helpers/ChatApp.js
Tim Alby 291f28a655 decaf cleanup: remove unnecessary use of Array.from
GitOrigin-RevId: 78c835929c9d7c38e0231f8fbb3e16a35efb7498
2022-01-14 09:02:50 +00:00

31 lines
699 B
JavaScript

const { waitForDb } = require('../../../../app/js/mongodb')
const app = require('../../../../app')
module.exports = {
running: false,
initing: false,
callbacks: [],
ensureRunning(callback) {
if (!callback) {
callback = function () {}
}
if (this.running) {
return callback()
} else if (this.initing) {
return this.callbacks.push(callback)
}
this.initing = true
this.callbacks.push(callback)
waitForDb().then(() => {
app.listen(3010, 'localhost', error => {
if (error) {
throw error
}
this.running = true
for (callback of this.callbacks) {
callback()
}
})
})
},
}