ProjectHistoryApp.js 1.1 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. import { app } from '../../../../app/js/server.js'
  12. import logger from '@overleaf/logger'
  13. logger.logger.level('error')
  14. let running = false
  15. let initing = false
  16. const callbacks = []
  17. export function ensureRunning(callback) {
  18. if (callback == null) {
  19. callback = function () {}
  20. }
  21. if (running) {
  22. return callback()
  23. } else if (initing) {
  24. return callbacks.push(callback)
  25. }
  26. initing = true
  27. callbacks.push(callback)
  28. app.listen(3054, 'localhost', error => {
  29. if (error != null) {
  30. throw error
  31. }
  32. running = true
  33. return (() => {
  34. const result = []
  35. for (callback of Array.from(callbacks)) {
  36. result.push(callback())
  37. }
  38. return result
  39. })()
  40. })
  41. }