Description
This syntax doesn't compile anymore in v1.12.0 and up:
#include <iostream>
#include <cpr/cpr.h>
int main() {
// Launch a long async GET request...
cpr::Session session{};
session.SetUrl(cpr::Url{"https://ash-speed.hetzner.com/1GB.bin"});
cpr::AsyncResponse future = session.GetAsync();
// Wait 1s
std::this_thread::sleep_for(std::chrono::seconds(1));
// Cancel request after 1s
if (not future.IsCancelled()) {
std::cout << "Cancelling..." << std::endl;
cpr::CancellationResult cr = future.Cancel();
switch (cr) {
case cpr::CancellationResult::failure:
std::cout << "failure" << std::endl;
break;
case cpr::CancellationResult::success:
std::cout << "success" << std::endl;
break;
case cpr::CancellationResult::invalid_operation:
std::cout << "invalid_operation" << std::endl;
break;
}
}
}
Compile error
/home/libcpr_cancelable/main.cpp: In function ‘int main()’:
/home/libcpr_cancelable/main.cpp:11:18: error: ‘using cpr::AsyncResponse = class cpr::AsyncWrapper<cpr::Response>’ {aka ‘class cpr::AsyncWrapper<cpr::Response>’} has no member named ‘IsCancelled’
11 | if (not future.IsCancelled()) {
| ^~~~~~~~~~~
/home/libcpr_cancelable/main.cpp:13:41: error: ‘using cpr::AsyncResponse = class cpr::AsyncWrapper<cpr::Response>’ {aka ‘class cpr::AsyncWrapper<cpr::Response>’} has no member named ‘Cancel’
13 | cpr::CancellationResult cr = future.Cancel();
| ^~~~~~
Did the api change recently? if so what will be the new way of cancelling async requests? Thank you.
Example/How to Reproduce
- Create a
cpr::Session
- Set option
cpr::Url("https://ash-speed.hetzner.com/1GB.bin") to slow down the response
- Perform an async GET request
- Cancel the async request after ~1s
- Compile and see compilation error
Possible Fix
No response
Where did you get it from?
GitHub (branch e.g. master)
Additional Context/Your Environment
- OS: Ubuntu
- Version: 24.04.1 LTS
Description
This syntax doesn't compile anymore in v1.12.0 and up:
Compile error
Did the api change recently? if so what will be the new way of cancelling async requests? Thank you.
Example/How to Reproduce
cpr::Sessioncpr::Url("https://ash-speed.hetzner.com/1GB.bin")to slow down the responsePossible Fix
No response
Where did you get it from?
GitHub (branch e.g. master)
Additional Context/Your Environment