File tree 2 files changed +19
-3
lines changed
2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ public class HTTPClient {
68
68
let eventLoopGroupProvider : EventLoopGroupProvider
69
69
let configuration : Configuration
70
70
let poolManager : HTTPConnectionPool . Manager
71
- var state : State
71
+ private var state : State
72
72
private let stateLock = Lock ( )
73
73
74
74
internal static let loggingDisabled = Logger ( label: " AHC-do-not-log " , factory: { _ in SwiftLogNoOpLogHandler ( ) } )
@@ -118,8 +118,14 @@ public class HTTPClient {
118
118
}
119
119
120
120
deinit {
121
- guard case . shutDown = self . state else {
122
- preconditionFailure ( " Client not shut down before the deinit. Please call client.syncShutdown() when no longer needed. " )
121
+ debugOnly {
122
+ // We want to crash only in debug mode.
123
+ switch self . state {
124
+ case . shutDown:
125
+ break
126
+ case . shuttingDown, . upAndRunning:
127
+ preconditionFailure ( " Client not shut down before the deinit. Please call client.syncShutdown() when no longer needed. " )
128
+ }
123
129
}
124
130
}
125
131
Original file line number Diff line number Diff line change @@ -32,3 +32,13 @@ public final class HTTPClientCopyingDelegate: HTTPClientResponseDelegate {
32
32
return ( )
33
33
}
34
34
}
35
+
36
+ /// A utility function that runs the body code only in debug builds, without
37
+ /// emitting compiler warnings.
38
+ ///
39
+ /// This is currently the only way to do this in Swift: see
40
+ /// https://forums.swift.org/t/support-debug-only-code/11037 for a discussion.
41
+ @inlinable
42
+ internal func debugOnly( _ body: ( ) -> Void ) {
43
+ assert ( { body ( ) ; return true } ( ) )
44
+ }
You can’t perform that action at this time.
0 commit comments