dxFeed Graal CXX API v4.3.1
Loading...
Searching...
No Matches
Promises Class Reference

A class that represents a promise-based implementation often used for handling asynchronous operations. More...

#include <Promises.hpp>

Static Public Member Functions

template<typename Collection>
static std::shared_ptr< Promise< void > > allOf (const Collection &collection)
 Returns a new promise that completes when all promises from the given collection complete normally or exceptionally.
 
template<typename Collection>
static std::shared_ptr< Promise< void > > allOf (std::shared_ptr< Collection > collection)
 Returns a new promise that completes when all promises from the given collection complete normally or exceptionally.
 
template<typename Collection>
static std::shared_ptr< Promise< void > > allOf (std::unique_ptr< Collection > collection)
 Returns a new promise that completes when all promises from the given collection complete normally or exceptionally.
 

Detailed Description

A class that represents a promise-based implementation often used for handling asynchronous operations.

This class provides a framework for handling asynchronous tasks by encapsulating the eventual success (resolution) or failure (rejection) of an operation. It enables chaining of asynchronous operations using methods like then, catch, and finally.

The Promises class is designed to streamline the processing of asynchronous workflows, reducing callback nesting and improving readability and maintainability of asynchronous code.

The functionality includes:

  • Resolving and rejecting a promise.
  • Attaching callbacks to handle resolved or rejected states.
  • Chaining operations to execute subsequent tasks in sequence.

The Promises class follows the native promise behavior in programming languages like JavaScript to facilitate deferred computation and eventual state handling.

Member Function Documentation

◆ allOf() [1/3]

template<typename Collection>
static std::shared_ptr< Promise< void > > Promises::allOf ( const Collection & collection)
inlinestatic

Returns a new promise that completes when all promises from the given collection complete normally or exceptionally.

The results of the given promises are not reflected in the returned promise, but may be obtained by inspecting them individually. If no promises are provided, returns a promise completed with the value void. When the resulting promise completes for any reason (is canceled, for example), then all the promises from the given array are canceled.

Template Parameters
CollectionThe collection type. For example, PromiseList<LastingEvent> (i.e., std::vector<Promise<std::shared_ptr<LastingEvent>>>) or std::vector<std::shared_ptr<Promise<std::shared_ptr<LastingEvent>>>>.
Parameters
collectionThe collection of promises or collection of pointer-likes of promises
Returns
A new promise that completes when all promises from the given array complete.

◆ allOf() [2/3]

template<typename Collection>
static std::shared_ptr< Promise< void > > Promises::allOf ( std::shared_ptr< Collection > collection)
inlinestatic

Returns a new promise that completes when all promises from the given collection complete normally or exceptionally.

The results of the given promises are not reflected in the returned promise, but may be obtained by inspecting them individually. If no promises are provided, returns a promise completed with the value void. When the resulting promise completes for any reason (is canceled, for example), then all the promises from the given array are canceled.

Template Parameters
CollectionThe collection type. For example, PromiseList<LastingEvent> (i.e., std::vector<Promise<std::shared_ptr<LastingEvent>>>) or std::vector<std::shared_ptr<Promise<std::shared_ptr<LastingEvent>>>>.
Parameters
collectionThe smart pointer to the collection of promises or collection of pointer-likes of promises
Returns
A new promise that completes when all promises from the given array complete.

◆ allOf() [3/3]

template<typename Collection>
static std::shared_ptr< Promise< void > > Promises::allOf ( std::unique_ptr< Collection > collection)
inlinestatic

Returns a new promise that completes when all promises from the given collection complete normally or exceptionally.

The results of the given promises are not reflected in the returned promise, but may be obtained by inspecting them individually. If no promises are provided, returns a promise completed with the value void. When the resulting promise completes for any reason (is canceled, for example), then all the promises from the given array are canceled.

Template Parameters
CollectionThe collection type. For example, PromiseList<LastingEvent> (i.e. std::vector<Promise<std::shared_ptr<LastingEvent>>>) or std::vector<std::shared_ptr<Promise<std::shared_ptr<LastingEvent>>>>.
Parameters
collectionThe smart pointer to the collection of promises or collection of pointer-likes of promises
Returns
A new promise that completes when all promises from the given array complete.