vapor / postgres-nio

🐘 Non-blocking, event-driven Swift client for PostgreSQL.
https://api.vapor.codes/postgresnio/documentation/postgresnio/
MIT License
317 stars 72 forks source link

Allow PostgresConnection creation without specifying an EventLoop #388

Closed fabianfett closed 1 year ago

fabianfett commented 1 year ago

SwiftNIO has landed EventLoopGroup singletons in 2.58.0. See https://github.com/apple/swift-nio/pull/2471.

We should add an additional PostgresConnection connect method, that internally uses the existing one, but uses the NIO singleton:

extension PostgresConnection {
    static func connect(
        configuration: PostgresConnection.Configuration,
        id connectionID: PostgresConnection.ID,
        logger: Logger
    ) async throws -> PostgresConnection {
        try await Self.connect(
            on: MultiThreadedEventLoopGroup.singleton.any(),
            configuration: configuration,
            id: connectionID,
            logger: logger
        )
    }
}