macro_rules! spawn_unresponsive_client_processor { ($const_config: expr, $channel_type: tt, $socket_client: expr, $remote_messages: ty, $local_messages: ty, $protocol_events_handler_fn: expr, $dialog_processor_builder_fn: expr) => { ... }; }
Expand description
Spawns a processor for a client (previously instantiated by new_composite_socket_client!()) that may communicate with the server using multiple protocols / multiple calls
to this macro with different parameters (or to its “responsive” variant) – finally calling CompositeSocketClient::start_multi_protocol() when the “Composite Protocol Stacking” is complete.
The given dialog_processor_builder_fn is a builder of “unresponsive” Streams, as specified in CompositeSocketClient::spawn_unresponsive_processor().
If you don’t need multiple protocols and don’t want to follow the “Composite Protocol Stacking” pattern, see the start_unresponsive_client_processor!() macro instead.
Params:
const_config: [ConstConfig] – the configurations for the client, enforcing const/compile time optimizations;channel_type: One of the followingreactive-mutinychannels to be used for message passing. EitherAtomic,FullSyncorCrossbeam;socket_client: CompositeSocketClient – The object returned by the call tonew_socket_client!();remote_messages: [ReactiveMessagingDeserializer<>] – the type of the messages produced by the server;local_messages: [ReactiveMessagingSerializer<>] – the type of the messages produced by this client – should, additionally, implement theDefaulttrait;protocol_events_handler_fn: async Fn – The callback that receives the connection/protocol events ProtocolEvent;dialog_processor_builder_fn: FnOnce – The builder for theStreamthat consumes server messages.
protocol_events_handler_fn – a generic function (or closure) to handle “new peer”, “peer left” and “service termination” events (possibly to manage sessions). Sign it as:
async fn protocol_events_handler<const CONFIG: u64,
LocalMessages: ReactiveMessagingSerializer<LocalMessages> + Send + Sync + PartialEq + Debug,
SenderChannel: FullDuplexUniChannel<ItemType=LocalMessages, DerivedItemType=LocalMessages> + Send + Sync>
(_event: ProtocolEvent<CONFIG, LocalMessages, SenderChannel, StateType>) {...}
dialog_processor_builder_fn – the generic function (or closure) that receives the Stream of remote messages and returns another Stream, which won’t
be sent out to peer(s) – called once for each connection. Sign it as:
fn unresponsive_processor<const CONFIG: u64,
LocalMessages: ReactiveMessagingSerializer<LocalMessages> + Send + Sync + PartialEq + Debug,
SenderChannel: FullDuplexUniChannel<ItemType=LocalMessages, DerivedItemType=LocalMessages> + Send + Sync,
StreamItemType: Deref<Target=[your type for messages produced by the CLIENT]>>
(peer_addr: String,
connected_port: u16,
peer: Arc<Peer<CONFIG, LocalMessages, SenderChannel, StateType>>,
remote_messages_stream: impl Stream<Item=StreamItemType>)
-> impl Stream<Item=()> {...}
Returns the handle that should be used by the closure given to [CompositeSocketClient::start_multi_protocol()] to refer to this processor / protocol.
For examples, please consult the unit tests at the end of this module.