ClsiApp.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. * DS103: Rewrite code to no longer use __guard__
  8. * DS205: Consider reworking code to avoid use of IIFEs
  9. * DS207: Consider shorter variations of null checks
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. const app = require('../../../../app')
  13. const Settings = require('@overleaf/settings')
  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. } else {
  27. this.initing = true
  28. this.callbacks.push(callback)
  29. return app.listen(
  30. Settings.internal.clsi.port,
  31. Settings.internal.clsi.host,
  32. error => {
  33. if (error != null) {
  34. throw error
  35. }
  36. this.running = true
  37. return (() => {
  38. const result = []
  39. for (callback of Array.from(this.callbacks)) {
  40. result.push(callback())
  41. }
  42. return result
  43. })()
  44. }
  45. )
  46. }
  47. },
  48. }