libcpr / cpr

C++ Requests: Curl for People, a spiritual port of Python Requests.
https://docs.libcpr.org/
Other
6.29k stars 903 forks source link

Add support for identifying whether a Session is currently busy or not #1027

Closed WSL-Ben closed 3 months ago

WSL-Ben commented 4 months ago

Is your feature request related to a problem?

I am trying to create a list of Sessions that can be re-used as long-running connections, and would like to know if there is a method that can be used to determine whether a specific Session is currently busy or not.

An example of something similar to what I want to do:

cpr::Session get_session() {
    for(auto& session : _sessions) {
      if(session->isBusy()){
        continue;
      }
      return session;
    }
}

Possible Solution

I have been unable to find any workaround or solution.

Alternatives

No response

Additional Context

No response

COM8 commented 3 months ago

You could use the async interface for that:

cpr::Session session;
cpr::AsyncResponse future = session.GetAsync();
// [...]
if(!future.valid() || future.wait_for(std::chrono::seconds{0}) == std::future_status::ready) {
   return session;
}