I am trying to execute the example of async-http-client
doku. But unfortunately the code in the closure is not executed. Why?
import AsyncHTTPClient
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
httpClient.get(url: "https://swift.org").whenComplete { result in
print (result)
switch result {
case .failure(let error):
print("failure")
case .success(let response):
if response.status == .ok {
print("success")
} else {
print("error in response")
}
}
}
In the console I get: Program ended with exit code: 0
. So it is executed with success. But there is no print statement in the console.
Thanks!
It is because the main thread is getting executed before the request is done so no print statement will get called unless you ask the main thread to wait for the httpclient
https://github.com/swift-server/async-http-client/issues/129