-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
61 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,35 @@ | ||
import Dispatch | ||
import Logging | ||
import NIOCore | ||
import NIOPosix | ||
import Vapor | ||
|
||
/// This extension is temporary and can be removed once Vapor gets this support. | ||
extension Vapor.Application { | ||
fileprivate static let baseExecutionQueue = DispatchQueue(label: "vapor.codes.entrypoint") | ||
|
||
fileprivate 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 { | ||
var env = try Environment.detect() | ||
try LoggingSystem.bootstrap(from: &env) | ||
|
||
let app = try await Application.make(env) | ||
defer { app.shutdown() } | ||
|
||
try await configure(app) | ||
// This attempts to install NIO as the Swift Concurrency global executor. | ||
// You can enable it if you'd like to reduce the amount of context switching between NIO and Swift Concurrency. | ||
// Note: this has caused issues with some libraries that use `.wait()` and cleanly shutting down. | ||
// If enabled, you should be careful about calling async functions before this point as it can cause assertion failures. | ||
let executorTakeoverSuccess = | ||
NIOSingletons.unsafeTryInstallSingletonPosixEventLoopGroupAsConcurrencyGlobalExecutor() | ||
app.logger.debug( | ||
"Tried to install SwiftNIO's EventLoopGroup as Swift's global concurrency executor", | ||
metadata: ["success": .stringConvertible(executorTakeoverSuccess)]) | ||
|
||
do { | ||
try await app.runFromAsyncMainEntrypoint() | ||
try await configure(app) | ||
} catch { | ||
exit(1) | ||
app.logger.report(error: error) | ||
try? await app.asyncShutdown() | ||
throw error | ||
} | ||
|
||
try await app.execute() | ||
try await app.asyncShutdown() | ||
} | ||
} |