C++ APISession methods

last_operation_took

Returns the cached duration of the most recently measured operation.

last_operation_took returns the cached duration of the most recently measured operation performed by the current blaze::session.

Function variants

std::chrono::milliseconds last_operation_took() const;

Cached metric only

last_operation_took does not start an operation and does not inspect session authorization state. It only returns the currently stored duration value.

Result

std::chrono::milliseconds
TypeMeaning
std::chrono::millisecondsDuration of the most recently measured operation for this session.

Behavior notes

  • Initial value is 0ms until the first measured operation completes.
  • The value is updated after connect() finishes, even if connect ends with an error.
  • The value is updated after ping() finishes once the ping/pong attempt actually runs.
  • The value is also updated when API operation handlers finish, before the library checks transport errors or response parsing errors.
  • Because of that, transport/protocol failures after a request was actually attempted can still update the cached duration.
  • For async_transfer_file(...), the cached value is updated as transfer packets arrive, so it reflects elapsed transfer time so far rather than per-chunk latency.
  • If an operation returns immediately from local validation or from an early pre-send failure, the previous cached value may remain unchanged.
  • Reading this value does not perform any network I/O.

Example

Compilation note

This example compiles in the same form from C++14 to C++26.

#include "blazeauth/api/api.hpp"

#include <iostream>
#include <string>
#include <system_error>

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;

  std::cout << "Before any operation: " << session.last_operation_took().count()
            << "ms\n";

  try {
    session.connect();
    std::cout << "Connect took: " << session.last_operation_took().count()
              << "ms\n";

    const blaze::application app =
      session.initialize("your-websocket-api-key", "your-client-id");
    if (!app.good()) {
      std::cout << "Initialize status: " << blaze::to_string(app.status) << '\n';
    }

    std::cout << "Initialize took: " << session.last_operation_took().count()
              << "ms\n";

    const std::chrono::milliseconds ping_rtt = session.ping();
    std::cout << "Ping returned: " << ping_rtt.count() << "ms\n";
    std::cout << "Cached last_operation_took(): "
              << session.last_operation_took().count() << "ms\n";

    session.shutdown();
  } catch (const std::system_error& e) {
    print_error_code("Operation failed", e.code());
    return 1;
  }

  return 0;
}

On this page