DocUpdaterApp.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. require('@overleaf/logger').logger.level('fatal')
  13. module.exports = {
  14. running: false,
  15. initing: false,
  16. callbacks: [],
  17. ensureRunning(callback) {
  18. if (callback == null) {
  19. callback = function () {}
  20. }
  21. if (this.running) {
  22. return callback()
  23. } else if (this.initing) {
  24. return this.callbacks.push(callback)
  25. }
  26. this.initing = true
  27. this.callbacks.push(callback)
  28. app.listen(3003, '127.0.0.1', error => {
  29. if (error != null) {
  30. throw error
  31. }
  32. this.running = true
  33. return (() => {
  34. const result = []
  35. for (callback of Array.from(this.callbacks)) {
  36. result.push(callback())
  37. }
  38. return result
  39. })()
  40. })
  41. },
  42. }