cpr icon indicating copy to clipboard operation
cpr copied to clipboard

Cancellable GetCallback and friends

Open ChrisDirkis opened this issue 2 years ago • 1 comments

Is your feature request related to a problem?

I'm trying to implement request cancellation for some requests done via GetCallback. Historically, we'd have a shared_ptr to a flag that's then checked in the callback, but I noticed that 1.10 had some cancellation semantics, so I was interested in using those instead. However, it appears that GetCallback and friends don't support cancellation, only MultiGetAsync and friends do.

Possible Solution

I'd like to see GetCallback be cancellable as MultiGetAsync is. It seems like cpr::async could return AsyncWrapper<T, true>, but the trivial change didn't compile and I haven't looked further into it.

Alternatively, I'd be happy to use MultiGetCallback with 1 request, if such existed.

Alternatives

For now, we can solve this on our end with some shared flag checked in the callback.

Additional Context

No response

ChrisDirkis avatar May 31 '23 05:05 ChrisDirkis

@ChrisDirkis Thanks for creating this feature request. I agree, this would be a nice feature. Performing an async request is minimal more expensive but definitely the way to go here. Else you could use the ProgressCallback and just return false based on a specific flag you store in your code. Docs: https://docs.libcpr.org/advanced-usage.html#setting-callbacks

I will add it onto the TODO list for our next release.

COM8 avatar May 31 '23 15:05 COM8