SObjectizer  5.8
Loading...
Searching...
No Matches
so-5.5.17: prepare_receive and prepare_select functions

Usage of ordinary forms of so_5::receive functions inside loops could be inefficient because of wasting resources on constructions of internal objects with descriptions of handlers on each receive() call. More efficient way is the preparation of all receive params and reusing them later. A combination of so_5::prepare_receive() and so_5::receive() allows us to do that.

Usage example:

auto prepared = so_5::prepare_receive(
so_5::from(ch).extract_n(10).empty_timeout(200ms),
some_handlers... );
...
while( !some_condition )
{
auto r = so_5::receive( prepared );
...
}
mchain_receive_params_t< mchain_props::msg_count_status_t::undefined > from(mchain_t chain)
A helper function for simplification of creation of mchain_receive_params instance.
Definition mchain.hpp:1595
prepared_receive_t< sizeof...(Handlers) > prepare_receive(const mchain_receive_params_t< Msg_Count_Status > &params, Handlers &&... handlers)
Create parameters for receive function to be used later.
Definition mchain.hpp:2045
mchain_receive_result_t receive(const mchain_receive_params_t< Msg_Count_Status > &params, Handlers &&... handlers)
Advanced version of receive from mchain.
Definition mchain.hpp:1883

The exactly same situation is for so_5::select functions: some resources are allocated on each call of ordinary so_5::select() function and deallocated at exit. This reallocation can be avoided by using so_5::prepare_select() and appropriate so_5::select() function:

auto prepared = so_5::prepare_select(
so_5::from_all().extract_n(10).empty_timeout(200ms),
case_( ch1, some_handlers... ),
case_( ch2, more_handlers... ),
case_( ch3, yet_more_handlers... ) );
...
while( !some_condition )
{
auto r = so_5::select( prepared );
...
}
mchain_select_params_t< mchain_props::msg_count_status_t::undefined > from_all()
Helper function for creation of mchain_select_params instance with default values.
mchain_select_result_t select(const mchain_select_params_t< Msg_Count_Status > &params, Cases &&... cases)
An advanced form of multi chain select.
prepared_select_t< sizeof...(Cases) > prepare_select(mchain_select_params_t< Msg_Count_Status > params, Cases &&... cases)
Create prepared select statement to be used later.