|
SObjectizer
5.8
|
Since v.5.5.16 there are two new so_5::select functions which allow to receive and handle messages from several mchains.
The first variant of select takes a timeout and a list of mchains and message handlers for them:
It checks the mchains and wait for no more than 500ms if all mchains are empty. If some mchain is not empty it extracts just one message from that mchain and tries to find an appropriate handler for it. If handler is found it is called. If a handler is not found then the message extracted will be thrown out without any processing.
If all mchains are empty even after the specified timeout then select will do nothing.
Simple form of select extract just one message from a mchain. Which non-empty mchain will be used for message extraction is not determined.
Please note that if there is just one non-empty mchain then simple select will return after extraction on just one message. This message could not be processed if there is no appropriate handler for it.
As with receive there are two special values which can be used as timeout:
so_5::no_wait specifies zero timeout. It means that receive will not wait if the mchain is empty;so_5::infinite_wait specifies unlimited waiting. The return from receive will be on arrival of any message. Or if the mchain is closed explicitly.There is also more advanced version of select which can receive and handle more than one message from mchains. It receives a so_5::mchain_select_params_t objects with list of conditions and returns control if any of those conditions becomes true. For example:
Both select versions return an object of so_5::mchain_receive_result_t type. Methods of that object allow to get number of extracted and handled messages, and also the status of select operation.
It is possible to use a mchain in several select on different threads at the same time.
NOTE! A mchain can be used inside just one case_ statement in select. If the same mchain is used in several case_ statements then the behaviour of select is undefined. Please note also that select do not checks uniqueness of mchains in case_ statements (for performance reasons).