File tree Expand file tree Collapse file tree 3 files changed +22
-12
lines changed Expand file tree Collapse file tree 3 files changed +22
-12
lines changed Original file line number Diff line number Diff line change @@ -404,7 +404,6 @@ class ConnectionPool {
404
404
}
405
405
}
406
406
407
- // FIXME: Should this be a precondition or an assertion?
408
407
private func preconditionIsOpened( ) {
409
408
self . stateLock. withLock {
410
409
precondition ( self . state. isClosed == false , " Attempting to use closed HTTP1ConnectionProvider " )
Original file line number Diff line number Diff line change @@ -262,16 +262,6 @@ public class HTTPClient {
262
262
delegate: Delegate ,
263
263
eventLoop eventLoopPreference: EventLoopPreference ,
264
264
deadline: NIODeadline ? = nil ) -> Task < Delegate . Response > {
265
- // FIXME: Is this correct to assert?
266
- self . stateLock. withLock {
267
- switch state {
268
- case . upAndRunning:
269
- break
270
- case . shuttingDown, . shutDown:
271
- assertionFailure ( " Attempting to execute a request on shutdown client " )
272
- }
273
- }
274
-
275
265
let taskEL : EventLoop
276
266
switch eventLoopPreference. preference {
277
267
case . indifferent:
@@ -286,6 +276,19 @@ public class HTTPClient {
286
276
taskEL = delegateEL
287
277
}
288
278
279
+ let failedTask : Task < Delegate . Response > ? = self . stateLock. withLock {
280
+ switch state {
281
+ case . upAndRunning:
282
+ return nil
283
+ case . shuttingDown, . shutDown:
284
+ return Task< Delegate . Response> . failedTask( eventLoop: taskEL, error: HTTPClientError . alreadyShutdown)
285
+ }
286
+ }
287
+
288
+ if let failedTask = failedTask {
289
+ return failedTask
290
+ }
291
+
289
292
let redirectHandler : RedirectHandler < Delegate . Response > ?
290
293
switch self . configuration. redirectConfiguration. configuration {
291
294
case . follow( let max, let allowCycles) :
Original file line number Diff line number Diff line change @@ -498,6 +498,12 @@ extension HTTPClient {
498
498
self . lock = Lock ( )
499
499
}
500
500
501
+ static func failedTask( eventLoop: EventLoop , error: Error ) -> Task < Response > {
502
+ let task = self . init ( eventLoop: eventLoop)
503
+ task. promise. fail ( error)
504
+ return task
505
+ }
506
+
501
507
/// `EventLoopFuture` for the response returned by this request.
502
508
public var futureResult : EventLoopFuture < Response > {
503
509
return self . promise. futureResult
@@ -564,7 +570,9 @@ extension HTTPClient {
564
570
}
565
571
566
572
} else {
567
- // TODO: This is only reached in some internal unit t
573
+ // TODO: This seems only reached in some internal unit test
574
+ // Maybe there could be a better handling in the future to make
575
+ // it an error outside of testing contexts
568
576
return self . eventLoop. makeSucceededFuture ( ( ) )
569
577
}
570
578
}
You can’t perform that action at this time.
0 commit comments