C++ APISession methods
with_timeout
Returns a session copy that uses a different timeout for synchronous operations.
with_timeout returns a copy of the current blaze::session with a different
timeout for synchronous operations.
Function variants
blaze::session with_timeout(std::chrono::milliseconds timeout);No network I/O here
with_timeout does not send any API packet and does not open a new
connection. It only returns another blaze::session object with a different
sync timeout configuration.
Result
blaze::session| Type | Meaning |
|---|---|
blaze::session | A copied session object that shares the same underlying session state, but uses a different timeout for synchronous methods. |
Behavior notes
with_timeoutreturns a copy of the currentblaze::session, not a brand-new independent session.- The returned object shares the same underlying connection/session state as the original object.
- The original object remains unchanged.
- The configured timeout affects synchronous methods that block waiting for completion, such as
connect(),initialize(),shutdown(), and similar sync API calls. - Asynchronous methods, coroutine methods, callbacks, and hooks are not driven by this timeout value.
- If
timeout <= 0ms, synchronous methods on the returned object wait indefinitely. - This method is most useful for one-off chaining such as
session.with_timeout(5s).initialize(...). - If you keep multiple copied
blaze::sessionobjects alive, remember that they still operate on the same underlying session lifecycle.
Example
Compilation note
This example compiles in the same form from C++14 to C++26.
#include "blazeauth/api/api.hpp"
#include <chrono>
#include <iostream>
#include <string>
#include <system_error>
using namespace std::chrono_literals;
void print_error_code(const std::string& context, const std::error_code& ec) {
std::cout << context << ": " << ec.message() << " ("
<< ec.value() << " : " << ec.category().name() << ")\n";
}
int main() {
blaze::session session;
try {
blaze::session fast_timeout = session.with_timeout(5s);
const blaze::api_server server = fast_timeout.connect();
std::cout << "Connected to server location: " << server.location << '\n';
// Original session object still refers to the same underlying connection.
if (session.is_connected()) {
std::cout << "Original session object sees the same live connection\n";
}
fast_timeout.shutdown();
} catch (const std::system_error& e) {
print_error_code("Operation failed", e.code());
return 1;
}
return 0;
}