ContactsApp.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // TODO: This file was created by bulk-decaffeinate.
  2. // Fix any style issues and re-enable lint.
  3. /*
  4. * decaffeinate suggestions:
  5. * DS101: Remove unnecessary use of Array.from
  6. * DS102: Remove unnecessary code created because of implicit returns
  7. * DS205: Consider reworking code to avoid use of IIFEs
  8. * DS207: Consider shorter variations of null checks
  9. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  10. */
  11. const app = require('../../../app')
  12. const { waitForDb } = require('../../../app/js/mongodb')
  13. require('@overleaf/logger').logger.level('error')
  14. module.exports = {
  15. running: false,
  16. initing: false,
  17. callbacks: [],
  18. ensureRunning(callback) {
  19. if (callback == null) {
  20. callback = function () {}
  21. }
  22. if (this.running) {
  23. return callback()
  24. } else if (this.initing) {
  25. return this.callbacks.push(callback)
  26. }
  27. this.initing = true
  28. this.callbacks.push(callback)
  29. waitForDb().then(() => {
  30. return app.listen(3036, 'localhost', error => {
  31. if (error != null) {
  32. throw error
  33. }
  34. this.running = true
  35. return (() => {
  36. const result = []
  37. for (callback of Array.from(this.callbacks)) {
  38. result.push(callback())
  39. }
  40. return result
  41. })()
  42. })
  43. })
  44. },
  45. }