Skip to content

Commit 6f3615c

Browse files
authored
Add support for pruning of idle pool connections (vapor#110)
* Buncha package cleanup, including adding ExistentialAny. * Add support for automatic pruning of idle database connections with configurable check interval and idle timeout. * Fix old Swift * Use logger metadata * Resolve API breakage warnings * Some tiny bits of cleanup
1 parent e048c8e commit 6f3615c

19 files changed

+502
-291
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ env:
1212

1313
jobs:
1414
unit-tests:
15-
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
15+
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
16+
secrets: inherit

Package.swift

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.7
1+
// swift-tools-version:5.10
22
import PackageDescription
33

44
let package = Package(
@@ -19,16 +19,33 @@ let package = Package(
1919
.package(url: "https://github.com/apple/swift-algorithms.git", from: "1.1.0"),
2020
],
2121
targets: [
22-
.target(name: "AsyncKit", dependencies: [
23-
.product(name: "Logging", package: "swift-log"),
24-
.product(name: "NIOCore", package: "swift-nio"),
25-
.product(name: "NIOEmbedded", package: "swift-nio"),
26-
.product(name: "NIOPosix", package: "swift-nio"),
27-
.product(name: "Collections", package: "swift-collections"),
28-
.product(name: "Algorithms", package: "swift-algorithms"),
29-
]),
30-
.testTarget(name: "AsyncKitTests", dependencies: [
31-
.target(name: "AsyncKit"),
32-
]),
22+
.target(
23+
name: "AsyncKit",
24+
dependencies: [
25+
.product(name: "Logging", package: "swift-log"),
26+
.product(name: "NIOCore", package: "swift-nio"),
27+
.product(name: "NIOEmbedded", package: "swift-nio"),
28+
.product(name: "NIOPosix", package: "swift-nio"),
29+
.product(name: "Collections", package: "swift-collections"),
30+
.product(name: "Algorithms", package: "swift-algorithms"),
31+
],
32+
swiftSettings: swiftSettings
33+
),
34+
.testTarget(
35+
name: "AsyncKitTests",
36+
dependencies: [
37+
.target(name: "AsyncKit"),
38+
],
39+
swiftSettings: swiftSettings
40+
),
3341
]
3442
)
43+
44+
var swiftSettings: [SwiftSetting] { [
45+
.enableUpcomingFeature("ExistentialAny"),
46+
.enableUpcomingFeature("ConciseMagicFile"),
47+
.enableUpcomingFeature("ForwardTrailingClosures"),
48+
//.enableUpcomingFeature("DisableOutwardActorInference"),
49+
.enableUpcomingFeature("MemberImportVisibility"),
50+
//.enableExperimentalFeature("StrictConcurrency=complete"),
51+
] }

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/vapor/async-kit/assets/1130717/1d4e3e08-b237-480b-913b-11d569f6f468">
44
<source media="(prefers-color-scheme: light)" srcset="https://github.com/vapor/async-kit/assets/1130717/abb01b9f-f6d2-46de-be5a-59d721211bee">
55
<img src="https://github.com/vapor/async-kit/assets/1130717/abb01b9f-f6d2-46de-be5a-59d721211bee" height="96" alt="AsyncKit">
6-
</picture>
6+
</picture>
77
<br>
88
<br>
9-
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg?1" alt="Documentation"></a>
9+
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg" alt="Documentation"></a>
1010
<a href="https://discord.gg/vapor"><img src="https://design.vapor.codes/images/discordchat.svg" alt="Team Chat"></a>
11-
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg?1" alt="MIT License"></a>
11+
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
1212
<a href="https://github.com/vapor/async-kit/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/async-kit/test.yml?event=push&style=plastic&logo=github&label=test&logoColor=%23ccc" alt="Continuous Integration"></a>
13-
<a href="https://codecov.io/github/vapor/async-kit"><img src="https://img.shields.io/codecov/c/github/vapor/async-kit?style=plastic&logo=codecov&label=Codecov&token=yDzzHja8lt"></a>
14-
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift57up.svg?1" alt="Swift 5.7+"></a>
13+
<a href="https://codecov.io/github/vapor/async-kit"><img src="https://img.shields.io/codecov/c/github/vapor/async-kit?style=plastic&logo=codecov&label=Codecov"></a>
14+
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift510up.svg" alt="Swift 5.10+"></a>
1515
</p>
1616

1717
<br>

Sources/AsyncKit/ConnectionPool/ConnectionPoolError.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
/// Errors thrown by `ConnectionPool`.
1+
/// Errors thrown by ``EventLoopGroupConnectionPool`` and ``EventLoopConnectionPool`` regarding state.
22
public enum ConnectionPoolError: Error {
33
/// The connection pool has shutdown.
44
case shutdown
55
}
66

7+
/// Errors thrown by ``EventLoopGroupConnectionPool`` and ``EventLoopConnectionPool`` regarding timeouts.
78
public enum ConnectionPoolTimeoutError: Error {
89
/// The connection request timed out.
910
case connectionRequestTimeout

Sources/AsyncKit/ConnectionPool/ConnectionPoolItem.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import NIOCore
22

33
/// Item managed by a connection pool.
44
public protocol ConnectionPoolItem: AnyObject {
5-
/// EventLoop this connection belongs to.
6-
var eventLoop: EventLoop { get }
7-
5+
/// `EventLoop` this connection belongs to.
6+
var eventLoop: any EventLoop { get }
7+
88
/// If `true`, this connection has closed.
99
var isClosed: Bool { get }
10-
10+
1111
/// Closes this connection.
1212
func close() -> EventLoopFuture<Void>
1313
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import NIOCore
22
import struct Logging.Logger
33

4-
/// Source of new connections for `ConnectionPool`.
4+
/// Source of new connections for ``EventLoopGroupConnectionPool``.
55
public protocol ConnectionPoolSource {
6-
/// Associated `ConnectionPoolItem` that will be returned by `makeConnection()`.
6+
/// Associated ``ConnectionPoolItem`` that will be returned by ``ConnectionPoolSource/makeConnection(logger:on:)``.
77
associatedtype Connection: ConnectionPoolItem
8-
8+
99
/// Creates a new connection.
10-
func makeConnection(logger: Logger, on eventLoop: EventLoop) -> EventLoopFuture<Connection>
10+
func makeConnection(logger: Logger, on eventLoop: any EventLoop) -> EventLoopFuture<Connection>
1111
}

0 commit comments

Comments
 (0)