ContactsApp.js 1.3 KB

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