virthttp  0.0
libvirt http interface
Classes | Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
AsyncStore Struct Reference

#include <async_store.hpp>

Classes

struct  Element
 

Public Types

enum  TaskStatus { TaskStatus::non_existent, TaskStatus::in_progress, TaskStatus::finished }
 
using IndexType = std::uint32_t
 Type used as the key to elems. More...
 
using ClockType = std::chrono::system_clock
 Type used for the expiration clock. More...
 

Public Member Functions

template<class Fcn >
std::optional< IndexTypelaunch (Fcn &&fcn, std::optional< std::chrono::seconds > expire_opt=std::nullopt)
 
std::pair< TaskStatus, std::string > value_if_ready (IndexType id)
 
void gc () noexcept
 

Public Attributes

std::mutex mut {}
 mutex to make elems thread-safe More...
 
std::unordered_map< IndexType, Elementelems
 actual container of entries More...
 
IndexType last_id {-1u}
 last allocated id; ids are incremental More...
 
std::chrono::seconds default_expire = 120s
 default entry expiration time More...
 

Static Public Attributes

static constexpr std::chrono::seconds init_expire = std::chrono::seconds::max()
 expiration since initial request until task completion More...
 

Detailed Description

Storage for asynchronous requests

Member Typedef Documentation

using AsyncStore::ClockType = std::chrono::system_clock

Type used for the expiration clock.

using AsyncStore::IndexType = std::uint32_t

Type used as the key to elems.

Member Enumeration Documentation

Status of a task; for messaging, not storage

Enumerator
non_existent 

task does not exist

in_progress 

task is currently being executed

finished 

task is done and its buffers are ready to be sent back

Member Function Documentation

void AsyncStore::gc ( )
inlinenoexcept

Discard expired entries

template<class Fcn >
std::optional<IndexType> AsyncStore::launch ( Fcn &&  fcn,
std::optional< std::chrono::seconds >  expire_opt = std::nullopt 
)
inline

Launches a task, optionally with a specified post-completion expiration time

Template Parameters
Fcn(deduced)
Parameters
[in]fcnthe callable to be called to obtain the response body
[in]expire_optan optional expiration time after task completion
Returns
the key to the newly created task in the store, or std::nullopt if the store is full

Note: when integrating deflate compression, add here as well

std::pair<TaskStatus, std::string> AsyncStore::value_if_ready ( IndexType  id)
inline

Get a task's status by key, and its response buffer if ready

Parameters
[in]idthe task's key
Returns
the task status and the associated buffer, which will be empty if the status is not TaskStatus::finished

Member Data Documentation

std::chrono::seconds AsyncStore::default_expire = 120s

default entry expiration time

std::unordered_map<IndexType, Element> AsyncStore::elems

actual container of entries

constexpr std::chrono::seconds AsyncStore::init_expire = std::chrono::seconds::max()
static

expiration since initial request until task completion

IndexType AsyncStore::last_id {-1u}

last allocated id; ids are incremental

std::mutex AsyncStore::mut {}

mutex to make elems thread-safe


The documentation for this struct was generated from the following file: