2023-12-06 09:49:26 +01:00
|
|
|
import Vapor
|
|
|
|
import Dispatch
|
|
|
|
import Logging
|
|
|
|
|
|
|
|
/// This extension is temporary and can be removed once Vapor gets this support.
|
|
|
|
private extension Vapor.Application {
|
|
|
|
static let baseExecutionQueue = DispatchQueue(label: "vapor.codes.entrypoint")
|
|
|
|
|
|
|
|
func runFromAsyncMainEntrypoint() async throws {
|
|
|
|
try await withCheckedThrowingContinuation { continuation in
|
|
|
|
Vapor.Application.baseExecutionQueue.async { [self] in
|
|
|
|
do {
|
|
|
|
try self.run()
|
|
|
|
continuation.resume()
|
|
|
|
} catch {
|
|
|
|
continuation.resume(throwing: error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@main
|
|
|
|
enum Entrypoint {
|
|
|
|
static func main() async throws {
|
2023-12-08 15:57:33 +01:00
|
|
|
var env = Environment.production
|
2023-12-06 09:49:26 +01:00
|
|
|
try LoggingSystem.bootstrap(from: &env)
|
|
|
|
|
|
|
|
let app = Application(env)
|
2023-12-08 15:57:33 +01:00
|
|
|
func cleanup() async {
|
|
|
|
await shutdown()
|
2023-12-06 09:49:26 +01:00
|
|
|
app.shutdown()
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
try await configure(app)
|
|
|
|
} catch {
|
|
|
|
app.logger.report(error: error)
|
2023-12-08 15:57:33 +01:00
|
|
|
await cleanup()
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
try await app.runFromAsyncMainEntrypoint()
|
|
|
|
await cleanup()
|
|
|
|
} catch {
|
|
|
|
await cleanup()
|
2023-12-06 09:49:26 +01:00
|
|
|
throw error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|