dxFeed Graal CXX API v4.0.0
Loading...
Searching...
No Matches
CommonPromiseMixin< P > Struct Template Reference

Mixin for wrapping calls to common promise methods. More...

#include <Promise.hpp>

Public Member Functions

bool isDone () const
 Returns true when computation has completed normally, or exceptionally, or was cancelled.
 
bool hasResult () const
 Returns true when computation has completed normally.
 
bool hasException () const
 Returns true when computation has completed exceptionally or was cancelled.
 
bool isCancelled () const
 Returns true when computation was cancelled.
 
JavaException getException () const
 Returns exceptional outcome of computation.
 
bool awaitWithoutException (std::int32_t timeoutInMilliseconds) const
 Wait for computation to complete or timeout or throw an exception in case of exceptional completion.
 
bool awaitWithoutException (const std::chrono::milliseconds &timeoutInMilliseconds) const
 Wait for computation to complete or timeout or throw an exception in case of exceptional completion.
 
void cancel () const
 Cancels computation.
 

Detailed Description

template<typename P>
struct CommonPromiseMixin< P >

Mixin for wrapping calls to common promise methods.

Template Parameters
PThe promise type

Member Function Documentation

◆ awaitWithoutException() [1/2]

template<typename P >
bool CommonPromiseMixin< P >::awaitWithoutException ( const std::chrono::milliseconds & timeoutInMilliseconds) const
inline

Wait for computation to complete or timeout or throw an exception in case of exceptional completion.

If the wait is interrupted, then the computation is cancelled, the interruption flag on the current thread is set, and "CancellationException" is thrown.

If the wait times out, then the computation is cancelled and this method returns false. Use this method in the code that shall continue normal execution in case of timeout.

Parameters
timeoutInMillisecondsThe timeout.
Returns
true if the computation has completed normally; false when wait timed out.
Exceptions
CancellationExceptionif computation was cancelled.
PromiseExceptionif computation has completed exceptionally.

◆ awaitWithoutException() [2/2]

template<typename P >
bool CommonPromiseMixin< P >::awaitWithoutException ( std::int32_t timeoutInMilliseconds) const
inline

Wait for computation to complete or timeout or throw an exception in case of exceptional completion.

If the wait is interrupted, then the computation is cancelled, the interruption flag on the current thread is set, and "CancellationException" is thrown.

If the wait times out, then the computation is cancelled and this method returns false. Use this method in the code that shall continue normal execution in case of timeout.

Parameters
timeoutInMillisecondsThe timeout.
Returns
true if the computation has completed normally; false when wait timed out.
Exceptions
CancellationExceptionif computation was cancelled.
PromiseExceptionif computation has completed exceptionally.

◆ cancel()

template<typename P >
void CommonPromiseMixin< P >::cancel ( ) const
inline

Cancels computation.

This method does nothing if computation has already completed.

If cancelled, then getException() will return "CancellationException", isDone, isCancelled, and hasException will return true, all handlers that were installed with whenDone method are notified by invoking their promiseDone method, and all waiters on join method throw "CancellationException".

◆ getException()

template<typename P >
JavaException CommonPromiseMixin< P >::getException ( ) const
inline

Returns exceptional outcome of computation.

If computation has no hasException() exception, then this method returns an exception with a message "null". If computation has completed exceptionally or was cancelled, then the result of this method is not an exception with a message "null". If computation was cancelled, then this method returns "an instance of CancellationException".

Returns
exceptional outcome of computation.
See also
hasException()

◆ hasException()

template<typename P >
bool CommonPromiseMixin< P >::hasException ( ) const
inline

Returns true when computation has completed exceptionally or was cancelled.

Use getException() method to get the exceptional outcome of the computation.

Returns
true when computation has completed exceptionally or was cancelled.

◆ hasResult()

template<typename P >
bool CommonPromiseMixin< P >::hasResult ( ) const
inline

Returns true when computation has completed normally.

Use ::getResult() method to get the result of the computation.

Returns
true when computation has completed normally.
See also
::getResult()

◆ isCancelled()

template<typename P >
bool CommonPromiseMixin< P >::isCancelled ( ) const
inline

Returns true when computation was cancelled.

Use getException() method to get the corresponding CancellationException.

Returns
true when computation was cancelled.
See also
getException()

◆ isDone()

template<typename P >
bool CommonPromiseMixin< P >::isDone ( ) const
inline

Returns true when computation has completed normally, or exceptionally, or was cancelled.

Returns
true when computation has completed.