DocUpdaterApp.js 1.4 KB

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