ChatApp.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 { waitForDb } = require('../../../../app/js/mongodb')
  12. const app = require('../../../../app')
  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. waitForDb().then(() => {
  29. return app.listen(3010, 'localhost', error => {
  30. if (error != null) {
  31. throw error
  32. }
  33. this.running = true
  34. return (() => {
  35. const result = []
  36. for (callback of Array.from(this.callbacks)) {
  37. result.push(callback())
  38. }
  39. return result
  40. })()
  41. })
  42. })
  43. },
  44. }