Shaka Player Embedded
Public Types | Public Member Functions | List of all members
shaka::AsyncResults< T > Class Template Referencefinal

#include <async_results.h>

Public Types

using result_type = typename std::conditional< std::is_same< T, void >::value, monostate, T >::type
 
using variant_type = variant< result_type, Error >
 

Public Member Functions

 AsyncResults ()
 
 AsyncResults (std::shared_future< variant_type > future)
 
 ~AsyncResults ()
 
bool valid () const
 
void wait ()
 
template<typename Rep , typename Period >
std::future_status wait_for (const std::chrono::duration< Rep, Period > &timeout_duration) const
 
template<typename Clock , typename Duration >
std::future_status wait_until (std::chrono::time_point< Clock, Duration > &timeout_time) const
 
bool has_error () const
 
template<typename U = T, typename = typename std::enable_if< !std::is_same<U, void>::value>::type>
const U & results () const
 
const Errorerror () const
 

Detailed Description

template<typename T>
class shaka::AsyncResults< T >

This represents the results of an asynchronous operation. This type is similar to a std::future. This stores either the resulting value of the operation or the Error object that occurred. AsyncResults<void> don't have results and only store the optional error.

Unlike std::future, this will block the destructor until the operation finishes. This means that if you don't store the results in a variable, the function becomes synchronous.

// Return value not stored, second load will not run until first finishes.
Player.Load();
Player.Load();

Definition at line 46 of file async_results.h.

Member Typedef Documentation

§ result_type

template<typename T>
using shaka::AsyncResults< T >::result_type = typename std::conditional<std::is_same<T, void>::value, monostate, T>::type

Definition at line 49 of file async_results.h.

§ variant_type

template<typename T>
using shaka::AsyncResults< T >::variant_type = variant<result_type, Error>

Definition at line 50 of file async_results.h.

Constructor & Destructor Documentation

§ AsyncResults() [1/2]

template<typename T>
shaka::AsyncResults< T >::AsyncResults ( )
inline

Creates an empty results object.

Definition at line 53 of file async_results.h.

§ AsyncResults() [2/2]

template<typename T>
shaka::AsyncResults< T >::AsyncResults ( std::shared_future< variant_type future)
inline

Creates an object that will wrap the given std::shared_future.

Definition at line 56 of file async_results.h.

§ ~AsyncResults()

template<typename T>
shaka::AsyncResults< T >::~AsyncResults ( )
inline

Definition at line 58 of file async_results.h.

Member Function Documentation

§ error()

template<typename T>
const Error& shaka::AsyncResults< T >::error ( ) const
inline

Blocks until the results are available and returns the error object. This is only valid if there is an error.

Definition at line 124 of file async_results.h.

§ has_error()

template<typename T>
bool shaka::AsyncResults< T >::has_error ( ) const
inline

Blocks until the results are available and returns whether this contains an error.

Definition at line 106 of file async_results.h.

§ results()

template<typename T>
template<typename U = T, typename = typename std::enable_if< !std::is_same<U, void>::value>::type>
const U& shaka::AsyncResults< T >::results ( ) const
inline

Blocks until the results are available and returns the response object. This is only valid if there isn't an error.

Definition at line 116 of file async_results.h.

§ valid()

template<typename T>
bool shaka::AsyncResults< T >::valid ( ) const
inline

Checks if the future refers to a shared state.

Definition at line 72 of file async_results.h.

§ wait()

template<typename T>
void shaka::AsyncResults< T >::wait ( )
inline

Waits until the results are available.

Definition at line 77 of file async_results.h.

§ wait_for()

template<typename T>
template<typename Rep , typename Period >
std::future_status shaka::AsyncResults< T >::wait_for ( const std::chrono::duration< Rep, Period > &  timeout_duration) const
inline

Waits for the results to be available, unless the given duration of time passes.

Definition at line 86 of file async_results.h.

§ wait_until()

template<typename T>
template<typename Clock , typename Duration >
std::future_status shaka::AsyncResults< T >::wait_until ( std::chrono::time_point< Clock, Duration > &  timeout_time) const
inline

Waits for the results to be available, unless it still isn't available when the given time happens.

Definition at line 96 of file async_results.h.


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