Skip to content

Commit 8fa354d

Browse files
authored
Merge branch 'master' into add_event_loop_in_execute
2 parents 1b7e97e + 6c6162b commit 8fa354d

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

README.md

+7-10
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ and `AsyncHTTPClient` dependency to your target:
2828
```
2929

3030
#### Request-Response API
31-
The code snippet below illustrates how to make a simple GET request to a remote server:
31+
32+
The code snippet below illustrates how to make a simple GET request to a remote server.
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.
3237

3338
```swift
3439
import AsyncHTTPClient
@@ -48,15 +53,7 @@ httpClient.get(url: "https://swift.org").whenComplete { result in
4853
}
4954
```
5055

51-
It is important to close the client instance, for example in a `defer` statement, after use to cleanly shutdown the underlying NIO `EventLoopGroup`:
52-
```swift
53-
try? httpClient.syncShutdown()
54-
```
55-
Alternatively, you can provide shared `EventLoopGroup`:
56-
```swift
57-
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(userProvidedGroup))
58-
```
59-
In this case shutdown of the client is not neccecary.
56+
You should always shut down `HTTPClient` instances you created using `try httpClient.syncShutdown()`. Please note that you must not call `httpClient.syncShutdown` before all requests of the HTTP client have finished, or else the in-flight requests will likely fail because their network connections are interrupted.
6057

6158
## Usage guide
6259

0 commit comments

Comments
 (0)