You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1003 B

  1. import Vapor
  2. import Dispatch
  3. import Logging
  4. /// This extension is temporary and can be removed once Vapor gets this support.
  5. private extension Vapor.Application {
  6. static let baseExecutionQueue = DispatchQueue(label: "vapor.codes.entrypoint")
  7. func runFromAsyncMainEntrypoint() async throws {
  8. try await withCheckedThrowingContinuation { continuation in
  9. Vapor.Application.baseExecutionQueue.async { [self] in
  10. do {
  11. try self.run()
  12. continuation.resume()
  13. } catch {
  14. continuation.resume(throwing: error)
  15. }
  16. }
  17. }
  18. }
  19. }
  20. @main
  21. enum Entrypoint {
  22. static func main() async throws {
  23. var env = try Environment.detect()
  24. try LoggingSystem.bootstrap(from: &env)
  25. let app = Application(env)
  26. defer { app.shutdown() }
  27. try await configure(app)
  28. try await app.runFromAsyncMainEntrypoint()
  29. }
  30. }