-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
whenComplete
does not work without wait()
#564
Comments
The problem is probably that Similar issue: #477 BTW: If you can use Swift async-http-client/Examples/GetJSON/GetJSON.swift Lines 36 to 50 in 71af9c7
|
Hi, ah okay thanks I guess this code works for now.. yeah for some reasons, i'm not able to use async/await for now let future = httpClient.execute(request: request)
defer {
_ = try? future.wait() // --> gotta discard the result here
try? httpClient.syncShutdown()
}
httpClient.execute(request: request).whenComplete { result in
dump(result)
switch result {
case .failure(let error):
print("Error \(error)")
case .success(let response):
print("Response: \(response)")
if response.status == .ok {
print("Response: \(response)")
} else {
print("Response is not ok")
}
}
} |
Hi, I'm new with swift-nio and want to make a simple swift cli tool that sends an API request. I tried following the readme to do something like this in my swift code
the output error is
One google result leads me to this same problem https://stackoverflow.com/questions/59434813/how-to-use-async-http-client
and the answer is, rather than using whenComplete , i should do it like this
How can I make the
whenComplete
works?When I just add a line
try future.wait()
... it works but i need to discard its response too?Thanks for your help!
The text was updated successfully, but these errors were encountered: