macro_rules! spawn_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 – and finally calling CompositeSocketClient::start_multi_protocol() when the “Composite Protocol Stacking” is complete.
The given dialog_processor_builder_fn
is a builder of Stream
s, as specified in CompositeSocketClient::spawn_processor().
If you don’t need multiple protocols and don’t want to follow the “Composite Protocol Stacking” pattern, see the start_client_processor!()
macro instead.
Params:
const_config
: [ConstConfig] – the configurations for the client, enforcing const/compile time optimizations;channel_type
: One of the followingreactive-mutiny
channels to be used for message passing. EitherAtomic
,FullSync
orCrossbeam
;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 theDefault
trait;protocol_events_handler_fn
: async Fn – The callback that receives the connection/protocol events ProtocolEvent;dialog_processor_builder_fn
: FnOnce – The builder for theStream
that 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) – called once for each connection – that receives the Stream
of remote messages and returns
another Stream
, that may be, optionally, sent out to the peer
(see crate::prelude::ResponsiveStream). Sign it as:
fn 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 SERVER]>>
(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.