Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
Loading...
Searching...
No Matches
helios::async::Future< T > Class Template Reference

Wrapper around tf::Future for handling asynchronous task results. More...

#include <future.hpp>

Public Member Functions

 Future ()=default
 
 Future (const Future &)=delete
 
 Future (Future &&other) noexcept=default
 
 ~Future ()=default
 
Futureoperator= (const Future &)=delete
 
Futureoperator= (Future &&other) noexcept=default
 
Get ()
 Blocks until the result is available and returns it.
 
bool Cancel ()
 Attempts to cancel the associated task.
 
void Wait ()
 Blocks until the result is available.
 
template<typename Rep , typename Period >
requires requires { typename std::chrono::duration<Rep, Period>; }
std::future_status WaitFor (const std::chrono::duration< Rep, Period > &rel_time) const
 Waits for the result to become available for the specified duration.
 
template<typename Clock , typename Duration >
requires requires { typename std::chrono::time_point<Clock, Duration>; }
std::future_status WaitUntil (const std::chrono::time_point< Clock, Duration > &abs_time) const
 Waits for the result to become available until the specified time point.
 
bool Valid () const
 Checks if the future has a shared state.
 

Friends

class Executor
 
class SubTaskGraph
 

Detailed Description

template<typename T>
class helios::async::Future< T >

Wrapper around tf::Future for handling asynchronous task results.

Provides methods to wait for and retrieve results from asynchronous operations. Move-only type that represents the eventual result of an async computation.

Note
All member functions are thread-safe.
Template Parameters
TThe type of value the future will hold

Definition at line 21 of file future.hpp.

Constructor & Destructor Documentation

◆ Future() [1/3]

template<typename T >
helios::async::Future< T >::Future ( )
default

◆ Future() [2/3]

template<typename T >
helios::async::Future< T >::Future ( const Future< T > &  )
delete

◆ Future() [3/3]

template<typename T >
helios::async::Future< T >::Future ( Future< T > &&  other)
defaultnoexcept

◆ ~Future()

template<typename T >
helios::async::Future< T >::~Future ( )
default

Member Function Documentation

◆ Cancel()

template<typename T >
bool helios::async::Future< T >::Cancel ( )
inline

Attempts to cancel the associated task.

May not succeed if the task has already started or completed.

Returns
True if cancellation was successful, false otherwise

Definition at line 43 of file future.hpp.

43{ return future_.cancel(); }

◆ Get()

template<typename T >
T helios::async::Future< T >::Get ( )
inline

Blocks until the result is available and returns it.

This method blocks the calling thread. Can only be called once.

Returns
The result of the asynchronous operation

Definition at line 36 of file future.hpp.

36{ return future_.get(); }

◆ operator=() [1/2]

template<typename T >
Future & helios::async::Future< T >::operator= ( const Future< T > &  )
delete

◆ operator=() [2/2]

template<typename T >
Future & helios::async::Future< T >::operator= ( Future< T > &&  other)
defaultnoexcept

◆ Valid()

template<typename T >
bool helios::async::Future< T >::Valid ( ) const
inline

Checks if the future has a shared state.

A future becomes invalid after Get() is called or if it was default-constructed.

Returns
True if the future is valid (has an associated task), false otherwise

Definition at line 82 of file future.hpp.

82{ return future_.valid(); }

◆ Wait()

template<typename T >
void helios::async::Future< T >::Wait ( )
inline

Blocks until the result is available.

Unlike Get(), this doesn't retrieve the result and can be called multiple times.

Definition at line 49 of file future.hpp.

49{ future_.wait(); }

◆ WaitFor()

template<typename T >
template<typename Rep , typename Period >
requires requires { typename std::chrono::duration<Rep, Period>; }
std::future_status helios::async::Future< T >::WaitFor ( const std::chrono::duration< Rep, Period > &  rel_time) const
inline

Waits for the result to become available for the specified duration.

Template Parameters
RepDuration representation type
PeriodDuration period type
Parameters
rel_timeMaximum time to wait
Returns
Status indicating whether the result is ready, timeout occurred, or task was deferred

Definition at line 60 of file future.hpp.

60 {
61 return future_.wait_for(rel_time);
62 }

◆ WaitUntil()

template<typename T >
template<typename Clock , typename Duration >
requires requires { typename std::chrono::time_point<Clock, Duration>; }
std::future_status helios::async::Future< T >::WaitUntil ( const std::chrono::time_point< Clock, Duration > &  abs_time) const
inline

Waits for the result to become available until the specified time point.

Template Parameters
ClockClock type
DurationDuration type
Parameters
abs_timeAbsolute time point to wait until
Returns
Status indicating whether the result is ready, timeout occurred, or task was deferred

Definition at line 73 of file future.hpp.

73 {
74 return future_.wait_until(abs_time);
75 }

Friends And Related Symbol Documentation

◆ Executor

template<typename T >
friend class Executor
friend

Definition at line 89 of file future.hpp.

◆ SubTaskGraph

template<typename T >
friend class SubTaskGraph
friend

Definition at line 90 of file future.hpp.