Public Types | |
typedef std::exception_ptr | FailureType |
typedef std::function< void(std::function< void()>)> | OnCancel |
typedef std::function< void()> | OnResolveHandler |
typedef std::function< void(FailureType const &)> | OnRejectHandler |
typedef std::function< void(OnResolveHandler const &, OnCancel const &)> | BasicInitializer |
typedef std::function< void(OnResolveHandler const &, OnRejectHandler const &, OnCancel const &)> | ComplexInitializer |
Public Types inherited from rili::Promise< void > | |
typedef std::exception_ptr | FailureType |
typedef std::function< void()> | OnResolveHandler |
typedef std::function< void(FailureType const &)> | OnRejectHandler |
typedef std::function< void(OnResolveHandler const &)> | BasicInitializer |
typedef std::function< void(OnResolveHandler const &, OnRejectHandler const &)> | ComplexInitializer |
Public Member Functions | |
CancelablePromise (BasicInitializer const &initializer) noexcept | |
CancelablePromise (ComplexInitializer const &initializer) noexcept | |
void | cancel () noexcept |
Public Member Functions inherited from rili::Promise< void > | |
Promise (BasicInitializer const &initializer) noexcept | |
Promise (ComplexInitializer const &initializer) noexcept | |
Promise () noexcept | |
Promise (FailureType const &rejected) noexcept | |
void | resolve () |
void | reject (FailureType const &rejected) |
template<typename OnSuccess , typename PromiseType = typename std::result_of<OnSuccess()>::type> | |
detail::GetPromiseType< PromiseType >::type | Then (OnSuccess const &onSuccess) noexcept |
template<typename OnSuccess , typename OnFailure , typename PromiseType1 = typename std::result_of<OnSuccess()>::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 |
Additional Inherited Members | |
Static Public Member Functions inherited from rili::Promise< void > | |
static rili::Promise< void > | all (std::list< rili::Promise< void >> const &promises) noexcept |
static rili::Promise< void > | any (std::list< rili::Promise< void >> const &promises) noexcept |
static rili::Promise< std::list< std::exception_ptr > > | fetch (std::list< rili::Promise< void >> const &promises) noexcept |
Detailed Description
template<>
class rili::CancelablePromise< void >
rili::CancelablePromise API allow easily chaining asynchronous actions to avoid "callback hell". Major difference between rili::CancelablePromise and A+ JS Promise
is chaining behavior using Catch method.
rili::CancelablePromise<void> add to rili::Promise<void> posibility to cancel it. Canceled promise will be rejected with rili::promise::PromiseCanceled error.
- Remarks
- is just specialization of rili::CancelablePromise for void type.
- is copiable, but copy share state with original instance.
- is generally thread safe and instances can be pass throught and shared by multiple threads.
- all operations (even Construction) are made asynchronous way and are non blocking.
- Warning
- if onCancel callback will be used, then registered handler will be invoked in case of any rejection including but ont only in case when rili::CancelablePromise<void>::cancel will be invoked. In addition it will be threated as plain error handler. When registered, if rili::CancelablePromise<void> will be rejected then std::terminate will not be called (even in case when other "outside" handlers are missing).
- Note
- rili::CancelablePromise<void> use rili::Context aquired during construction to dispatch asynchronously all further tasks(including chained children promises), so thread in which rili::CancelablePromise<void> is created may be important in some cases.
- rili::CancelablePromise<void> can be rejected or resolved only once - further reject or resolve will be skipped.
- Warning
- There cannot be rejected rili::CancelablePromise<void> which don't have (now or in future) rejection handlers, or rili::CancelablePromise<void>, which is not rejected nor resolved. Check for this is made in debug builds (assert is used) in rili::CancelablePromise<void> destructor.
Member Typedef Documentation
typedef std::function<void(OnResolveHandler const&, OnCancel const&)> rili::CancelablePromise< void >::BasicInitializer |
type of user callback for two parameter 'pending' rili::CancelablePromise<void> constructor
typedef std::function<void(OnResolveHandler const&, OnRejectHandler const&, OnCancel const&)> rili::CancelablePromise< void >::ComplexInitializer |
type of user callback for three parameter 'pending' rili::CancelablePromise<void> constructor
typedef std::exception_ptr rili::CancelablePromise< void >::FailureType |
is type in which all kinds of rejections / exceptions are stored in rili::CancelablePromise<void>
typedef std::function<void(std::function<void()>)> rili::CancelablePromise< void >::OnCancel |
can be used to register cancelation handler for pending rili::CancelablePromise<void>
typedef std::function<void(FailureType const&)> rili::CancelablePromise< void >::OnRejectHandler |
can be used to reject rili::CancelablePromise<void>
typedef std::function<void()> rili::CancelablePromise< void >::OnResolveHandler |
can be used to resolve rili::CancelablePromise<void>
Constructor & Destructor Documentation
|
explicitnoexcept |
Create 'pending' rili::CancelablePromise<void>.
Call user provided function with callback as paramether which should be used to resolve rili::CancelablePromise and second one, which can be used to register handler for cancelations.
- Remarks
- User provided callback will be executed asynchronously
- is not blocking.
- is thread safe.
- Note
- If user provided function throw, then rili::CancelablePromise<void> is moved to rejected state with error equal to thrown exception.
- Warning
- If callback 'resolve' will not be called nor exception thrown, then rili::CancelablePromise<void> will stay in 'pending' state infinitely, which will block rili::Context::run infinitely (eventualy it can be canceled which is equal to 'reject').
- Parameters
-
initializer is executed to resolve or reject rili::CancelablePromise<void>. It provide as parameter another function which can be used to resolve rili::CancelablePromise<void>, second reject and third to register cancelation handler.
Example:
|
explicitnoexcept |
Create 'pending' rili::CancelablePromise<void>.
Call user provided function with first parameter as callback which should be used to resolve rili::CancelablePromise<void>, second which should be used to reject it and third which can be used to register handler for cancelations.
- Remarks
- User provided callback will be executed asynchronously
- is not blocking.
- is thread safe.
- Note
- If user provided function throw, then rili::CancelablePromise<void> 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::CancelablePromise<void> will stay in 'pending' state infinitely, which will block rili::Context::run infinitely (eventualy it can be canceled which is equal to 'reject').
- Parameters
-
initializer is function which is executed to resolve or reject rili::CancelablePromise<void>. It provide as first parameter another function which can be used to resolve rili::CancelablePromise<void>, as second function which can be used to reject rili::CancelablePromise<void> and third to register cancelation handler.
Example:
Member Function Documentation
|
noexcept |
can be used to cancel rili::CancelablePromise<void>.
As result it will be immediately rejected with rili::promise::PromiseCanceled error, if is not already 'rejected' or 'resolved'
- Remarks
- is not blocking.
- is thread safe.
The documentation for this class was generated from the following file: