|  | 
|  | Promise (PromisedType const &promised) noexcept | 
|  | 
|  | Promise (FailureType const &rejected) noexcept | 
|  | 
|  | Promise (BasicInitializer const &initializer) noexcept | 
|  | 
|  | Promise (ComplexInitializer const &initializer) noexcept | 
|  | 
| void | resolve (PromisedType const &resolved) | 
|  | 
| void | reject (FailureType const &rejected) | 
|  | 
| template<typename OnSuccess , typename PromiseType  = typename std::result_of<OnSuccess(PromisedType const&)>::type> | 
| detail::GetPromiseType< PromiseType >::type | Then (OnSuccess const &onSuccess) noexcept | 
|  | 
| template<typename OnSuccess , typename OnFailure , typename PromiseType1  = typename std::result_of<OnSuccess(PromisedType const&)>::type, typename PromiseType2  = typename std::result_of<OnFailure(FailureType const&)>::type> | 
| detail::GetPromiseType< PromiseType1 >::type | Then (OnSuccess const &onSuccess, OnFailure const &onFailure) noexcept | 
|  | 
| template<typename OnFailure , typename PromiseType  = typename std::result_of<OnFailure(FailureType const&)>::type> | 
| detail::GetPromiseType< PromiseType >::type | Catch (OnFailure const &onFailure) noexcept | 
|  | 
| template<typename OnCompleted , typename PromiseType  = typename std::result_of<OnCompleted()>::type> | 
| detail::GetPromiseType< PromiseType >::type | Finally (OnCompleted const &onCompleted) noexcept | 
|  | 
template<typename PromisedType>
class rili::Promise< PromisedType >
rili::Promise API allow easily chaining asynchronous actions to avoid "callback hell".
- Note
- PromisedTypemust be copyable and copy assignable.
- 
rili::Promise use rili::Context aquired during construction to dispatch asynchronously all further tasks(including chained children promises), so thread in which rili::Promise is created may be important in some cases. 
- 
rili::Promise can be rejected or resolved only once - further reject or resolve will be skipped.
- Warning
- There cannot be rejected rili::Promise which don't have (now or in future) rejection handlers, or rili::Promise, which is not rejected nor resolved. Check for this is made in debug builds (assert is used) in rili::Promise destructor.
- See also
- rili::Context 
- 
rili::Promise<void> 
- 
rili::CancelablePromise 
- 
rili::CancelablePromise<void> 
template<typename PromisedType > 
      
 
type of user callback for single parameter 'pending' rili::Promise constructor 
 
 
template<typename PromisedType > 
      
 
type of user callback for two parameter 'pending' rili::Promise constructor 
 
 
template<typename PromisedType > 
      
 
is type in which all kinds of rejections / exceptions are stored in rili::Promise 
 
 
template<typename PromisedType > 
      
 
 
template<typename PromisedType > 
      
 
 
template<typename PromisedType > 
 
Create 'resolved' rili::Promise with promised value. 
- Parameters
- 
  
    | promised | is value using which rili::Promise should be constructed with 'resolved' state (without pending in meantime). |  
 
Example: 
 
 
 
template<typename PromisedType> 
 
Create 'rejected' rili::Promise with rejected value. 
- Parameters
- 
  
    | rejected | is error using which rili::Promise should be constructed with 'rejected' state (without pending in meantime). |  
 
Example: 
 
 
 
template<typename PromisedType > 
 
Create 'pending' rili::Promise. 
Call user provided function with callback as paramether which should be used to resolve rili::Promise.
- Note
- If user provided function throw, then rili::Promise is moved to rejected state with error equal to thrown exception.
- Warning
- If callback 'resolve' will not be called nor exception thrown then rili::Promise will stay in 'pending' state infinitely which will block rili::Context::run infinitely.
- Parameters
- 
  
    | initializer | is function which is executed to resolve or reject rili::Promise. It provide as parameter another function which can be used to resolve rili::Promise. |  
 
Example: 
 
 
 
template<typename PromisedType > 
 
Create 'pending' rili::Promise. 
Call user provided function with first parameter as callback which should be used to resolve rili::Promise and second which should be used to reject it.
- Note
- If user provided function throw, then rili::Promise is moved to rejected state with error equal to thrown exception.
- Warning
- If callback 'resolve' or 'reject' will not be called nor exception thrown, then rili::Promise will stay in 'pending' state infinitely, which will block rili::Context::run infinitely.
- Parameters
- 
  
    | initializer | is function which is executed to resolve or reject rili::Promise. It provide as first parameter another function which can be used to resolve rili::Promise and as second function which can be used to reject rili::Promise. |  
 
Example: 
    reject(std::make_exception_ptr(
"Huston, we have a problem!!!"));
 });
 
 
template<typename PromisedType> 
 
 
template<typename PromisedType> 
 
 
template<typename PromisedType> 
template<typename OnFailure , typename PromiseType  = typename std::result_of<OnFailure(FailureType const&)>::type> 
  
  | 
        
          | detail::GetPromiseType<PromiseType>::type rili::Promise< PromisedType >::Catch | ( | OnFailure const & | onFailure | ) |  |  | inlinenoexcept | 
 
Allow to create chained rili::Promise for failure scenario. 
It is used to branch execution path in case of failures.
- Parameters
- 
  
    | onFailure | callback will be called only when current rili::Promise will be rejected. It can return next rili::Promise or type value(which must be convertiable to current rili::Promise). |  
 
- Returns
- new rili::Promise chained to current one with type deduced based on current rili::Promise return type. 
 
 
template<typename PromisedType> 
 
 
template<typename PromisedType> 
template<typename OnCompleted , typename PromiseType  = typename std::result_of<OnCompleted()>::type> 
  
  | 
        
          | detail::GetPromiseType<PromiseType>::type rili::Promise< PromisedType >::Finally | ( | OnCompleted const & | onCompleted | ) |  |  | inlinenoexcept | 
 
Allow to create chained rili::Promise for 'completion' scenario. 
It is used when result of operation is not interesting - only it completion.
- In case when current rili::Promise will be rejected, then immediately and asynchronously onCompleted will be called.
- In case when current rili::Promise will be resolved, then immediately and asynchronously onCompleted will be called.
- Parameters
- 
  
    | onCompleted | callback will be called when current rili::Promise will be rejected or resolved. It can return next rili::Promise or other type value(which will be converted to resolved rili::Promise) inluding void type. |  
 
- Returns
- new rili::Promise chained to current one with type deduced based on onCompleted return type. 
 
 
template<typename PromisedType> 
 
allow to reject rili::Promise if not resolved/rejected yet 
- Parameters
- 
  
  
 
 
template<typename PromisedType> 
  
  | 
        
          | void rili::Promise< PromisedType >::resolve | ( | PromisedType const & | resolved | ) |  |  | inline | 
 
allow to resolve rili::Promise if not resolved/rejected yet 
- Parameters
- 
  
  
 
 
template<typename PromisedType> 
template<typename OnSuccess , typename PromiseType  = typename std::result_of<OnSuccess(PromisedType const&)>::type> 
  
  | 
        
          | detail::GetPromiseType<PromiseType>::type rili::Promise< PromisedType >::Then | ( | OnSuccess const & | onSuccess | ) |  |  | inlinenoexcept | 
 
Allow to create chained rili::Promise for succesfull scenario. 
- In case when current rili::Promise will be resolved, then immediately and asynchronously onSuccess will be called with current rili::Promise 'resolve' result as parameter.
- In case when current rili::Promise will be rejected, then rili::Promise created by this method will be also rejected.
- Parameters
- 
  
    | onSuccess | callback will be called only when current rili::Promise will be resolved. It can return next rili::Promise or other type value(which will be converted to resolved rili::Promise) inluding void type. |  
 
- Returns
- new rili::Promise chained to current one with type deduced based on onSucces return type. 
 
 
template<typename PromisedType> 
template<typename OnSuccess , typename OnFailure , typename PromiseType1  = typename std::result_of<OnSuccess(PromisedType const&)>::type, typename PromiseType2  = typename std::result_of<OnFailure(FailureType const&)>::type> 
  
  | 
        
          | detail::GetPromiseType<PromiseType1>::type rili::Promise< PromisedType >::Then | ( | OnSuccess const & | onSuccess, |  
          |  |  | OnFailure const & | onFailure |  
          |  | ) |  |  |  | inlinenoexcept | 
 
Allow to create chained rili::Promise for succesfull and Failure scenario. 
Is used when branching further execution path is not needed and failure handling will be implemented in onFailure.
- In case when current rili::Promise will be resolved, then immediately and asynchronously onSuccess will be called with current rili::Promise 'resolve' result as parameter.
- In case when current rili::Promise will be rejected, then immediately and asynchronously onFailure will be called with current rili::Promise 'reject' error as parameter.
Examples of correct combinations:
Examples of incorrect combinations:
- Parameters
- 
  
    | onSuccess | callback will be called only when current rili::Promise will be resolved. It can return next rili::Promise or other type value(which will be converted to resolved rili::Promise) inluding void type. |  | onFailure | callback will be called only when current rili::Promise will be rejected. It can return next rili::Promise or other type value(which will be converted to resolved rili::Promise) inluding void type. |  
 
- Returns
- new rili::Promise chained to current one with type deduced based on onSucces and onFailure return type. 
 
 
The documentation for this class was generated from the following file: