Macro start_client_processor

Source
macro_rules! start_client_processor {
    ($const_config:                 expr,
     $channel_type:                 tt,
     $socket_client:                expr,
     $remote_messages:              ty,
     $local_messages:               ty,
     $connection_events_handler_fn: expr,
     $dialog_processor_builder_fn:  expr) => { ... };
}
Expand description

Starts a client (previously instantiated by new_socket_client!()) that will communicate with the server using a single protocol – as defined by the given dialog_processor_builder_fn, a builder of Streams as specified in CompositeSocketClient::spawn_processor().

If you want to follow the “Composite Protocol Stacking” pattern, see the [spawn_composite_client_processor!()] macro instead.

Params:

  • const_config: [ConstConfig] – the configurations for the client, enforcing const/compile time optimizations;
  • channel_type: One of the following reactive-mutiny channels to be used for message passing. Either Atomic, FullSync or Crossbeam;
  • socket_client: CompositeSocketClient – The object returned by the call to new_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 the Default trait;
  • connection_events_handler_fn: async Fn – The callback that receives the connection/protocol events ProtocolEvent;
  • dialog_processor_builder_fn: FnOnce – The builder for the Stream that consumes server messages.

connection_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 connection_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 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 SERVER]>>
                             (peer_addr:              String,
                              connected_port:         u16,
                              peer:                   Arc<Peer<CONFIG, LocalMessages, SenderChannel, StateType>>,
                              remote_messages_stream: impl Stream<Item=StreamItemType>)
                             -> impl Stream<Item=ANY_TYPE> {...}

For examples, please consult the unit tests at the end of this module.