ChatApp.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 { waitForDb } = require('../../../../app/js/mongodb')
  15. const app = require('../../../../app')
  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. }
  29. this.initing = true
  30. this.callbacks.push(callback)
  31. waitForDb().then(() => {
  32. return app.listen(3010, 'localhost', 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. }