dispenso
A library for task parallelism
 
Loading...
Searching...
No Matches
dispenso::AsyncRequest< T > Class Template Reference

#include <async_request.h>

Public Types

using OpResult = detail::OpResult< T >
 

Public Member Functions

void requestUpdate ()
 
bool updateRequested () const
 
template<typename... Args>
bool tryEmplaceUpdate (Args &&... args)
 
OpResult getUpdate ()
 

Detailed Description

template<typename T>
class dispenso::AsyncRequest< T >

A type for making async requests. Although it is safe to use from multiple producers and consumers, it is primarily intended to be used from single producer, single consumer.

Typically the consumer will request an update of the value from thread 0, and the producer will look whether an update was requested from thread 1. Once the producer determines an update was requested (updateRequested() returns true), it calls tryEmplaceUpdate() to update the underlying data. Then when the consumer on thread 0 next calls getUpdate(), an optional wrapper to the updated data is returned, and the AsyncRequest object is reset (it no longer has valid data, and no update will have yet been requested for the next update).

Definition at line 38 of file async_request.h.

Member Typedef Documentation

◆ OpResult

template<typename T >
using dispenso::AsyncRequest< T >::OpResult = detail::OpResult<T>

Definition at line 44 of file async_request.h.

Member Function Documentation

◆ getUpdate()

template<typename T >
OpResult dispenso::AsyncRequest< T >::getUpdate ( )
inline

The consumer can attempt to get an update.

Returns
An optional wrapper to the underlying data. If no update is ready, nullopt is returned. Once an update has been returned, the AsyncRequest object is returned to a state with no underlying data.

Definition at line 90 of file async_request.h.

◆ requestUpdate()

template<typename T >
void dispenso::AsyncRequest< T >::requestUpdate ( )
inline

The consumer can call this to request an update to the underlying data. If request has already been made or fulfilled, this is a no-op.

Definition at line 51 of file async_request.h.

◆ tryEmplaceUpdate()

template<typename T >
template<typename... Args>
bool dispenso::AsyncRequest< T >::tryEmplaceUpdate ( Args &&...  args)
inline

The producer can try to emplace a new T object in response to a request.

Parameters
argsThe arguments to emplace.
Returns
true if the underlying data was updated. false if the underlying data is not in need of an update.
Note
For cases where calling this superflously could be expensive, it is wise to check updateRequested() first.

Definition at line 74 of file async_request.h.

◆ updateRequested()

template<typename T >
bool dispenso::AsyncRequest< T >::updateRequested ( ) const
inline

The producer can check this to determine if an update is needed.

Returns
true if an update is required, false otherwise.

Definition at line 61 of file async_request.h.


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