Skip to content

Commit 643a0dc

Browse files
authored
Added default value for queue in HTTPClient.shutdown() (#279)
Default it to .global()
1 parent 9c1c62b commit 643a0dc

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Sources/AsyncHTTPClient/HTTPClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public class HTTPClient {
164164
/// callback instead of an EventLoopFuture. The reason for that is that NIO's EventLoopFutures will call back on an event loop.
165165
/// The virtue of this function is to shut the event loop down. To work around that we call back on a DispatchQueue
166166
/// instead.
167-
public func shutdown(queue: DispatchQueue, _ callback: @escaping (Error?) -> Void) {
167+
public func shutdown(queue: DispatchQueue = .global(), _ callback: @escaping (Error?) -> Void) {
168168
self.shutdown(requiresCleanClose: false, queue: queue, callback)
169169
}
170170

Tests/AsyncHTTPClientTests/HTTPClientTests+XCTest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ extension HTTPClientTests {
103103
("testRacePoolIdleConnectionsAndGet", testRacePoolIdleConnectionsAndGet),
104104
("testAvoidLeakingTLSHandshakeCompletionPromise", testAvoidLeakingTLSHandshakeCompletionPromise),
105105
("testAsyncShutdown", testAsyncShutdown),
106+
("testAsyncShutdownDefaultQueue", testAsyncShutdownDefaultQueue),
106107
("testValidationErrorsAreSurfaced", testValidationErrorsAreSurfaced),
107108
("testUploadsReallyStream", testUploadsReallyStream),
108109
("testUploadStreamingCallinToleratedFromOtsideEL", testUploadStreamingCallinToleratedFromOtsideEL),

Tests/AsyncHTTPClientTests/HTTPClientTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,18 @@ class HTTPClientTests: XCTestCase {
17991799
XCTAssertNoThrow(try promise.futureResult.wait())
18001800
}
18011801

1802+
func testAsyncShutdownDefaultQueue() throws {
1803+
let localClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup))
1804+
let promise = self.clientGroup.next().makePromise(of: Void.self)
1805+
self.clientGroup.next().execute {
1806+
localClient.shutdown { error in
1807+
XCTAssertNil(error)
1808+
promise.succeed(())
1809+
}
1810+
}
1811+
XCTAssertNoThrow(try promise.futureResult.wait())
1812+
}
1813+
18021814
func testValidationErrorsAreSurfaced() throws {
18031815
let request = try HTTPClient.Request(url: self.defaultHTTPBinURLPrefix + "get", method: .TRACE, body: .stream { _ in
18041816
self.defaultClient.eventLoopGroup.next().makeSucceededFuture(())

0 commit comments

Comments
 (0)