template<std::size_t Size,
typename Extra_Data_Factory = no_extra_data_factory_t>
class restinio::async_chain::fixed_size_chain_t< Size, Extra_Data_Factory >
A holder of fixed-size chain of asynchronous handlers.
- Note
- An instance of that type is intended to be filled with actual schedulers at the creation time. After that new schedulers can't be added to the chain, and old handlers can't be removed from the chain.
Usage example for the case when there is no extra-data in a request object (please note that this is simplified example without actual asynchronous code, all schedulers work as synchronous handlers):
};
{
...
}
{
...
}
{
...
}
.address(...)
.port(...)
.request_handler(
);
A holder of fixed-size chain of asynchronous handlers.
constexpr schedule_result_t ok() noexcept
Helper function to be used if scheduling was successful.
void next(unique_async_handling_controller_t< Extra_Data_Factory > controller)
Command to try to switch to the next handler in an async chain.
schedule_result_t
Type for return value of a scheduler in a chain.
std::unique_ptr< async_handling_controller_t< Extra_Data_Factory > > unique_async_handling_controller_t
Short alias for unique_ptr to async_handling_controller.
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.
void run(asio_ns::io_context &ioctx, run_on_this_thread_settings_t< Traits > &&settings)
Helper function for running http server until ctrl+c is hit.
An instance of fixed_size_chain_t
can also be created manually and passed to server's settings by unique_ptr
:
auto chain = std::make_unique<restinio::async_chain::fixed_size_chain_t<3>>(
...
restinio::run(
.address(...)
.port(...)
.request_handler(std::move(
chain))
);
Usage example for the case when some extra-data is incorporated into a request object (please note that this is simplified example without actual asynchronous code, all schedulers work as synchronous handlers):
struct request_specific_fields_t {...};
struct user_info_t {...};
using data_t = std::tuple<request_specific_fields_t, user_info_t>;
}
};
using extra_data_factory_t = my_extra_data_factory;
3,
extra_data_factory>;
};
{
...
...
}
{
...
...
}
{
auto &
field_values = std::get<my_extra_data_factory::request_specific_fields_t>(
req->extra_data());
auto &
user_info = std::get<my_extra_data_factory::user_info_t>(
req->extra_data());
...
}
.address(...)
.port(...)
.request_handler(
);
- Template Parameters
-
Size | The exact number of schedulers in the chain. |
Extra_Data_Factory | The type of extra-data-factory specified in the server's traits. |
- Since
- v.0.7.0
- Examples
- sample/async_chained_handlers/main.cpp.
Definition at line 179 of file fixed_size.hpp.