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