RESTinio
Namespaces | Classes | Typedefs | Enumerations | Functions
restinio::async_chain Namespace Reference

Namespaces

 impl
 

Classes

class  async_handling_controller_t
 Interface of a controller of an async chan. More...
 
class  fixed_size_chain_t
 A holder of fixed-size chain of asynchronous handlers. More...
 
class  growable_size_chain_t
 A holder of variable-size chain of asynchronous handlers. More...
 
struct  no_more_schedulers_t
 Special type to be used as an indicator that there are no more schedulers in an async chain. More...
 

Typedefs

template<typename Extra_Data_Factory = no_extra_data_factory_t>
using unique_async_handling_controller_t = std::unique_ptr< async_handling_controller_t< Extra_Data_Factory > >
 Short alias for unique_ptr to async_handling_controller. More...
 
template<typename Extra_Data_Factory = no_extra_data_factory_t>
using generic_async_request_scheduler_t = std::function< schedule_result_t(unique_async_handling_controller_t< Extra_Data_Factory >) >
 Short alias for a type of a scheduler to be used in async chains. More...
 
template<typename Extra_Data_Factory = no_extra_data_factory_t>
using on_next_result_t = std::variant< generic_async_request_scheduler_t< Extra_Data_Factory >, no_more_schedulers_t >
 Special type to be used as result of async_handling_controller's on_next method. More...
 

Enumerations

enum  schedule_result_t { schedule_result_t::ok, schedule_result_t::failure }
 Type for return value of a scheduler in a chain. More...
 

Functions

constexpr schedule_result_t ok () noexcept
 Helper function to be used if scheduling was successful. More...
 
constexpr schedule_result_t failure () noexcept
 Helper function to be used if scheduling failed. More...
 
template<typename Extra_Data_Factory >
void next (unique_async_handling_controller_t< Extra_Data_Factory > controller)
 Command to try to switch to the next handler in an async chain. More...
 

Typedef Documentation

◆ generic_async_request_scheduler_t

template<typename Extra_Data_Factory = no_extra_data_factory_t>
using restinio::async_chain::generic_async_request_scheduler_t = typedef std::function< schedule_result_t(unique_async_handling_controller_t<Extra_Data_Factory>) >

Short alias for a type of a scheduler to be used in async chains.

Since
v.0.7.0

Definition at line 96 of file common.hpp.

◆ on_next_result_t

template<typename Extra_Data_Factory = no_extra_data_factory_t>
using restinio::async_chain::on_next_result_t = typedef std::variant< generic_async_request_scheduler_t< Extra_Data_Factory >, no_more_schedulers_t >

Special type to be used as result of async_handling_controller's on_next method.

The async_handling_controller_t::on_next may return an actual scheduler to be called or (if there are no more handlers left) a special no_more_handler value. This is described by on_next_result_t variant type.

Since
v.0.7.0

Definition at line 122 of file common.hpp.

◆ unique_async_handling_controller_t

template<typename Extra_Data_Factory = no_extra_data_factory_t>
using restinio::async_chain::unique_async_handling_controller_t = typedef std::unique_ptr< async_handling_controller_t< Extra_Data_Factory > >

Short alias for unique_ptr to async_handling_controller.

Since
v.0.7.0

Definition at line 85 of file common.hpp.

Enumeration Type Documentation

◆ schedule_result_t

Type for return value of a scheduler in a chain.

A scheduler should schedule the actual processing of a request and should tell whether this scheduling was successful or not. If it was successful, schedule_result_t::ok must be returned, otherwise the schedule_result_t::failure must be returned.

Since
v.0.7.0
Enumerator
ok 

The scheduling of the actual processing was successful.

failure 

The scheduling of the actual processing failed. Note, that there is no additional information about the failure.

Definition at line 24 of file common.hpp.

Function Documentation

◆ failure()

constexpr schedule_result_t restinio::async_chain::failure ( )
inlinenoexcept

Helper function to be used if scheduling failed.

Usage example:

builder.add([this](auto controller) {
try {
... // Actual scheduling.
return restinio::async_chain::ok(); // OK, no problems.
}
catch( ... ) {
}
});
Since
v.0.7.0

Definition at line 72 of file common.hpp.

◆ next()

template<typename Extra_Data_Factory >
void restinio::async_chain::next ( unique_async_handling_controller_t< Extra_Data_Factory >  controller)

Command to try to switch to the next handler in an async chain.

If an intermediate handler in an async chain doesn't complete processing of the request it should call next() function to activate the next handler in the chain.

If there are no more handlers in the chain the processing of the request will be finished just inside the next() call by generating negative response.

Note
The handler must not call next() if it generates the response for the request:
const auto req = controller->request_handle();
if(request_can_be_handled(req)) {
processing_of_the_request(req);
req->create_response(...)
...
.done(); // Request processing completed.
}
else {
// This handler can't complete processing of the request.
// Have to switch to the next handler.
next(std::move(controller));
}
// NOTE: it's not safe to use `controller` here!
}
Since
v.0.7.0
Examples:
sample/async_chained_handlers/main.cpp.

Definition at line 327 of file common.hpp.

◆ ok()

constexpr schedule_result_t restinio::async_chain::ok ( )
inlinenoexcept

Helper function to be used if scheduling was successful.

Usage example:

builder.add([this](auto controller) {
... // Actual scheduling.
});
Since
v.0.7.0
Examples:
sample/async_chained_handlers/main.cpp.

Definition at line 49 of file common.hpp.