pub fn sync_client_protocol(
    mem_pool: Arc<Mutex<MemPool>>,
    shutdown_event: broadcast::Sender<()>,
) -> ProtocolMeta {
    let spawn = FnSpawn(move |context, control, read_part| {
        let mem_pool = mem_pool.clone();
        let control = control.clone();
        let session_id = context.id;
        let mut shutdown_event_rx = shutdown_event.subscribe();
        tokio::spawn(async move {
            let result = tokio::select! {
                _ = shutdown_event_rx.recv() => return,
                result = sync_client(&mem_pool, session_id, &control, read_part) => result,
            };
            if let Err(e) = result {
                tracing::warn!(error = %e);
            }
            tracing::info!("sync_client ended");
            warn_result(control.disconnect(session_id).await);
        });
    });
    MetaBuilder::new()
        .name(|_| P2P_MEM_BLOCK_SYNC_PROTOCOL_NAME.into())
        .id(P2P_MEM_BLOCK_SYNC_PROTOCOL)
        .protocol_spawn(spawn)
        .build()
}
// Cooperate with graceful shutdown so that mem_pool can be dropped.
Cooperate with graceful shutdown so that mem_pool can be dropped.
Cooperate with graceful shutdown so that mem_pool can be dropped .
pub fn sync_client_protocol(
    mem_pool: Arc<Mutex<MemPool>>,
    shutdown_event: broadcast::Sender<()>,
) -> ProtocolMeta {
    let spawn = FnSpawn(move |context, control, read_part| {
        let mem_pool = mem_pool.clone();
        let control = control.clone();
        let session_id = context.id;
        let mut shutdown_event_rx = shutdown_event.subscribe();
        tokio::spawn(async move {
            let result = tokio::select! {
                _ = shutdown_event_rx.recv() => return,
                result = sync_client(&mem_pool, session_id, &control, read_part) => result,
            };
            if let Err(e) = result {
                tracing::warn!(error = %e);
            }
            tracing::info!("sync_client ended");
            warn_result(control.disconnect(session_id).await);
        });
    });
    MetaBuilder::new()
        .name(|_| P2P_MEM_BLOCK_SYNC_PROTOCOL_NAME.into())
        .id(P2P_MEM_BLOCK_SYNC_PROTOCOL)
        .protocol_spawn(spawn)
        .build()
}
pub fn sync_client_protocol ( mem_pool : Arc < Mutex < MemPool > > , shutdown_event : broadcast :: Sender < ( ) > , ) -> ProtocolMeta { let spawn = FnSpawn ( move | context , control , read_part | { let mem_pool = mem_pool . clone ( ) ; let control = control . clone ( ) ; let session_id = context . id ; let mut shutdown_event_rx = shutdown_event . subscribe ( ) ; tokio :: spawn ( async move { let result = tokio :: select ! { shutdown_event_rx recv ( ) return result sync_client ( mem_pool session_id control read_part ) result } ; if let Err ( e ) = result { tracing :: warn ! ( error e ) ; } tracing :: info ! ( " " ) ; warn_result ( control . disconnect ( session_id ) . await ) ; } ) ; } ) ; MetaBuilder :: new ( ) . name ( | _ | P2P_MEM_BLOCK_SYNC_PROTOCOL_NAME . into ( ) ) . id ( P2P_MEM_BLOCK_SYNC_PROTOCOL ) . protocol_spawn ( spawn ) . build ( ) }
Cooperate with graceful shutdown so that mem_pool can be dropped.
Cooperate with graceful shutdown so that mem_pool can be dropped .
mem_pool
Arc<Mutex<MemPool>>
shutdown_event
broadcast::Sender<()>
mem_pool
Arc<Mutex<MemPool>>
shutdown_event
broadcast::Sender<()>