No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

53 líneas
1.5 KiB

  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. }
  31. extension Application {
  32. static let entrypointQueue = DispatchQueue(label: "app.entrypoint")
  33. func runAsync() async throws {
  34. nonisolated(unsafe) let app = self
  35. try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
  36. Application.entrypointQueue.async {
  37. do {
  38. try app.run()
  39. continuation.resume()
  40. } catch {
  41. continuation.resume(throwing: error)
  42. }
  43. }
  44. }
  45. }
  46. }