-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathPoolStateMachine.swift
74 lines (60 loc) · 2.01 KB
/
PoolStateMachine.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#if canImport(Darwin)
import Darwin
#else
import Glibc
#endif
@usableFromInline
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
struct PoolConfiguration {
/// The minimum number of connections to preserve in the pool.
///
/// If the pool is mostly idle and the remote servers closes idle connections,
/// the `ConnectionPool` will initiate new outbound connections proactively
/// to avoid the number of available connections dropping below this number.
@usableFromInline
var minimumConnectionCount: Int = 0
/// The maximum number of connections to for this pool, to be preserved.
@usableFromInline
var maximumConnectionSoftLimit: Int = 10
@usableFromInline
var maximumConnectionHardLimit: Int = 10
@usableFromInline
var keepAliveDuration: Duration?
@usableFromInline
var idleTimeoutDuration: Duration = .seconds(30)
}
@usableFromInline
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
struct PoolStateMachine<
Connection: PooledConnection,
ConnectionIDGenerator: ConnectionIDGeneratorProtocol,
ConnectionID: Hashable & Sendable,
Request: ConnectionRequestProtocol,
RequestID,
TimerCancellationToken
> where Connection.ID == ConnectionID, ConnectionIDGenerator.ID == ConnectionID, RequestID == Request.ID {
@usableFromInline
struct Timer: Hashable, Sendable {
@usableFromInline
enum Usecase: Sendable {
case backoff
case idleTimeout
case keepAlive
}
@usableFromInline
var connectionID: ConnectionID
@usableFromInline
var timerID: Int
@usableFromInline
var duration: Duration
@usableFromInline
var usecase: Usecase
@inlinable
init(connectionID: ConnectionID, timerID: Int, duration: Duration, usecase: Usecase) {
self.connectionID = connectionID
self.timerID = timerID
self.duration = duration
self.usecase = usecase
}
}
}