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
+10-14
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: .globalSingleton)
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: .globalSingleton)
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
-4
Original file line number
Diff line number
Diff line change
@@ -31,10 +31,6 @@ 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.
/// Shuts down the ``HTTPClient`` and releases its resources.
217
-
///
218
-
/// - note: You cannot use this method if you sharted the ``HTTPClient`` with
219
-
/// `init(eventLoopGroupProvider: .createNew)` because that will shut down the `EventLoopGroup` the
220
-
/// returned future would run in.
221
219
publicfunc shutdown()->EventLoopFuture<Void>{
222
-
switchself.eventLoopGroupProvider {
223
-
case.shared(let group):
224
-
letpromise= group.any().makePromise(of:Void.self)
225
-
self.shutdown(queue:.global()){ error in
226
-
iflet error = error {
227
-
promise.fail(error)
228
-
}else{
229
-
promise.succeed(())
230
-
}
231
-
}
232
-
return promise.futureResult
233
-
case.createNew:
234
-
preconditionFailure("Cannot use the shutdown() method which returns a future when owning the EventLoopGroup. Please use the one of the other shutdown methods.")
/// `EventLoopGroup` will be provided by the user. Owner of this group is responsible for its lifecycle.
855
815
case shared(EventLoopGroup)
856
-
/// `EventLoopGroup` will be created by the client. When ``HTTPClient/syncShutdown()`` is called, the created `EventLoopGroup` will be shut down as well.
857
-
casecreateNew
816
+
/// An `EventLoopGroup` from `NIOSingletons`.
817
+
caseglobalSingleton
858
818
}
859
819
860
820
/// Specifies how the library will treat the event loop passed by the user.
0 commit comments