RESTinio
Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Enumerations | Functions
restinio::async_chain Namespace Reference

Namespaces

namespace  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
 Short alias for unique_ptr to async_handling_controller.
 
template<typename Extra_Data_Factory = no_extra_data_factory_t>
using generic_async_request_scheduler_t
 Short alias for a type of a scheduler to be used in async chains.
 
template<typename Extra_Data_Factory = no_extra_data_factory_t>
using on_next_result_t
 Special type to be used as result of async_handling_controller's on_next method.
 

Enumerations

enum class  schedule_result_t { ok , 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.
 
constexpr schedule_result_t failure () noexcept
 Helper function to be used if scheduling failed.
 
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.
 

Typedef Documentation

◆ generic_async_request_scheduler_t

Initial value:
std::function<
schedule_result_t(unique_async_handling_controller_t<Extra_Data_Factory>)
>
schedule_result_t
Type for return value of a scheduler in a chain.
Definition common.hpp:25

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

Since
v.0.7.0

Definition at line 93 of file common.hpp.

◆ on_next_result_t

Initial value:
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 119 of file common.hpp.

◆ unique_async_handling_controller_t

Initial value:
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 84 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 ( )
inlineconstexprnoexcept

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( ... ) {
}
});
A builder of an instance of growable_size_chain.
void add(Scheduler &&scheduler)
Add a new scheduler to the chain.
constexpr schedule_result_t ok() noexcept
Helper function to be used if scheduling was successful.
Definition common.hpp:49
constexpr schedule_result_t failure() noexcept
Helper function to be used if scheduling failed.
Definition common.hpp:72
run_on_this_thread_settings_t< Traits > on_this_thread()
A special marker for the case when http_server must be run on the context of the current thread.
Since
v.0.7.0

Definition at line 72 of file common.hpp.

◆ next()

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();
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!
}
void next(unique_async_handling_controller_t< Extra_Data_Factory > controller)
Command to try to switch to the next handler in an async chain.
Definition common.hpp:327
std::unique_ptr< async_handling_controller_t< Extra_Data_Factory > > unique_async_handling_controller_t
Short alias for unique_ptr to async_handling_controller.
Definition common.hpp:84
Since
v.0.7.0

Definition at line 327 of file common.hpp.

◆ ok()

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

Helper function to be used if scheduling was successful.

Usage example:

Since
v.0.7.0
Examples
sample/async_chained_handlers/main.cpp.

Definition at line 49 of file common.hpp.