ORIGINAL
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
original::async::sharedFuture< TYPE > Class Template Reference

Represents a sharable asynchronous result. More...

#include <async.h>

Inheritance diagram for original::async::sharedFuture< TYPE >:
Inheritance graph
Collaboration diagram for original::async::sharedFuture< TYPE >:
Collaboration graph

Public Member Functions

 sharedFuture (const sharedFuture &)=default
 
sharedFutureoperator= (const sharedFuture &)=default
 
 sharedFuture (sharedFuture &&)=default
 
sharedFutureoperator= (sharedFuture &&)=default
 
bool valid () const noexcept override
 Checks if the shared future is valid (has an associated async wrapper)
 
TYPE result () const
 Gets the result value (blocks until ready)
 
strongPtr< const TYPEstrongPointer () const
 Gets a strong pointer to the result value.
 
bool ready () const override
 Checks if the result is ready.
 
std::exception_ptr exception () const noexcept override
 Gets the exception if computation failed.
 
bool operator== (const sharedFuture &other) const noexcept
 Equality comparison operator.
 
bool operator!= (const sharedFuture &other) const noexcept
 Inequality comparison operator.
 
void wait () const override
 Waits until the result becomes ready.
 
bool waitFor (time::duration timeout) const override
 Waits for the result with a timeout.
 
u_integer toHash () const noexcept override
 Generates a hash value for the shared future.
 
bool equals (const sharedFuture &other) const noexcept override
 Checks if two shared futures are equal.
 
- Public Member Functions inherited from original::hashable< sharedFuture< TYPE > >
virtual bool equals (const sharedFuture< TYPE > &other) const noexcept
 Compares two objects for equality.
 
virtual ~hashable ()=0
 Virtual destructor.
 

Friends

class async
 

Detailed Description

template<typename TYPE>
class original::async::sharedFuture< TYPE >

Represents a sharable asynchronous result.

Template Parameters
TYPEThe result type of the computation

Unlike future, sharedFuture can be copied and safely stored in multiple places. All copies refer to the same asynchronous result, making it suitable for scenarios where results are needed by multiple consumers.

Member Function Documentation

◆ equals()

template<typename TYPE >
bool original::async::sharedFuture< TYPE >::equals ( const sharedFuture< TYPE > &  other) const
overridenoexcept

Checks if two shared futures are equal.

Parameters
otherThe other shared future to compare with
Returns
True if both shared futures refer to the same async wrapper

◆ exception()

template<typename TYPE >
std::exception_ptr original::async::sharedFuture< TYPE >::exception ( ) const
overridevirtualnoexcept

Gets the exception if computation failed.

Returns
Exception pointer (nullptr if no exception)

Implements original::async::futureBase.

◆ operator!=()

template<typename TYPE >
bool original::async::sharedFuture< TYPE >::operator!= ( const sharedFuture< TYPE > &  other) const
noexcept

Inequality comparison operator.

Parameters
otherThe other shared future to compare with
Returns
True if shared futures refer to different async wrappers

◆ operator==()

template<typename TYPE >
bool original::async::sharedFuture< TYPE >::operator== ( const sharedFuture< TYPE > &  other) const
noexcept

Equality comparison operator.

Parameters
otherThe other shared future to compare with
Returns
True if both shared futures refer to the same async wrapper

◆ ready()

template<typename TYPE >
bool original::async::sharedFuture< TYPE >::ready ( ) const
overridevirtual

Checks if the result is ready.

Returns
True if result is available

Implements original::async::futureBase.

◆ result()

template<typename TYPE >
TYPE original::async::sharedFuture< TYPE >::result ( ) const

Gets the result value (blocks until ready)

Returns
The computed result
Exceptions
std::exceptionif the computation threw an exception

◆ strongPointer()

template<typename TYPE >
original::strongPtr< const TYPE > original::async::sharedFuture< TYPE >::strongPointer ( ) const

Gets a strong pointer to the result value.

Returns a strong reference pointer to the asynchronous result, extending the lifetime of the referenced object and avoiding dangling references. The pointer approach avoids unnecessary copying

Warning
the returned pointer directly references the result stored within the async module. Modifying the stored result through constCastTo or other means may cause unexpected behavior and is strongly discouraged.
Returns
Strong pointer to the const result value
Exceptions
sysErrorif the shared future is invalid or not ready
std::exceptionif the computation threw an exception

◆ toHash()

template<typename TYPE >
original::u_integer original::async::sharedFuture< TYPE >::toHash ( ) const
overridevirtualnoexcept

Generates a hash value for the shared future.

Returns
Hash value based on the async wrapper pointer

Reimplemented from original::hashable< sharedFuture< TYPE > >.

◆ valid()

template<typename TYPE >
bool original::async::sharedFuture< TYPE >::valid ( ) const
overridevirtualnoexcept

Checks if the shared future is valid (has an associated async wrapper)

Returns
True if valid, false otherwise

Implements original::async::futureBase.

◆ wait()

template<typename TYPE >
void original::async::sharedFuture< TYPE >::wait ( ) const
overridevirtual

Waits until the result becomes ready.

Implements original::async::futureBase.

◆ waitFor()

template<typename TYPE >
bool original::async::sharedFuture< TYPE >::waitFor ( time::duration  timeout) const
overridevirtual

Waits for the result with a timeout.

Parameters
timeoutMaximum time to wait
Returns
True if result is ready within timeout, false otherwise

Implements original::async::futureBase.


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