You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-15Lines changed: 12 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -27,14 +27,10 @@ and `AsyncHTTPClient` dependency to your target:
27
27
28
28
The code snippet below illustrates how to make a simple GET request to a remote server.
29
29
30
-
Please note that the example will spawn a new `EventLoopGroup` which will _create fresh threads_ which is a very costly operation. In a real-world application that uses [SwiftNIO](https://github.com/apple/swift-nio) for other parts of your application (for example a web server), please prefer `eventLoopGroupProvider: .shared(myExistingEventLoopGroup)` to share the `EventLoopGroup` used by AsyncHTTPClient with other parts of your application.
31
-
32
-
If your application does not use SwiftNIO yet, it is acceptable to use `eventLoopGroupProvider: .createNew` but please make sure to share the returned `HTTPClient` instance throughout your whole application. Do not create a large number of `HTTPClient` instances with `eventLoopGroupProvider: .createNew`, this is very wasteful and might exhaust the resources of your program.
33
-
34
30
```swift
35
31
importAsyncHTTPClient
36
32
37
-
let httpClient =HTTPClient(eventLoopGroupProvider: .createNew)
33
+
let httpClient =HTTPClient(eventLoopGroupProvider: .singleton)
38
34
39
35
/// MARK: - Using Swift Concurrency
40
36
let request =HTTPClientRequest(url: "https://apple.com/")
@@ -78,7 +74,7 @@ The default HTTP Method is `GET`. In case you need to have more control over the
78
74
```swift
79
75
importAsyncHTTPClient
80
76
81
-
let httpClient =HTTPClient(eventLoopGroupProvider: .createNew)
77
+
let httpClient =HTTPClient(eventLoopGroupProvider: .singleton)
82
78
do {
83
79
var request =HTTPClientRequest(url: "https://apple.com/")
Copy file name to clipboardExpand all lines: Sources/AsyncHTTPClient/Docs.docc/index.md
+41-15Lines changed: 41 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -31,14 +31,14 @@ and `AsyncHTTPClient` dependency to your target:
31
31
32
32
The code snippet below illustrates how to make a simple GET request to a remote server.
33
33
34
-
Please note that the example will spawn a new `EventLoopGroup` which will _create fresh threads_ which is a very costly operation. In a real-world application that uses [SwiftNIO](https://github.com/apple/swift-nio) for other parts of your application (for example a web server), please prefer `eventLoopGroupProvider: .shared(myExistingEventLoopGroup)` to share the `EventLoopGroup` used by AsyncHTTPClient with other parts of your application.
35
-
36
-
If your application does not use SwiftNIO yet, it is acceptable to use `eventLoopGroupProvider: .createNew` but please make sure to share the returned `HTTPClient` instance throughout your whole application. Do not create a large number of `HTTPClient` instances with `eventLoopGroupProvider: .createNew`, this is very wasteful and might exhaust the resources of your program.
37
-
38
34
```swift
39
35
importAsyncHTTPClient
40
36
41
-
let httpClient =HTTPClient(eventLoopGroupProvider: .createNew)
37
+
let httpClient =HTTPClient(eventLoopGroupProvider: .singleton)
38
+
defer {
39
+
// Shutdown is guaranteed to work if it's done precisely once (which is the case here).
40
+
try! httpClient.syncShutdown()
41
+
}
42
42
43
43
/// MARK: - Using Swift Concurrency
44
44
let request =HTTPClientRequest(url: "https://apple.com/")
@@ -82,7 +82,12 @@ The default HTTP Method is `GET`. In case you need to have more control over the
82
82
```swift
83
83
importAsyncHTTPClient
84
84
85
-
let httpClient =HTTPClient(eventLoopGroupProvider: .createNew)
85
+
let httpClient =HTTPClient(eventLoopGroupProvider: .singleton)
86
+
defer {
87
+
// Shutdown is guaranteed to work if it's done precisely once (which is the case here).
88
+
try! httpClient.syncShutdown()
89
+
}
90
+
86
91
do {
87
92
var request =HTTPClientRequest(url: "https://apple.com/")
0 commit comments