/// Serve incoming connections using the provided backing `storage`.
Serve incoming connections using the provided backing `storage`.
Serve incoming connections using the provided backing ` storage ` .
async fn serve_connections(
    connections: impl Stream<Item = IncomingService> + 'static,
    storage: &mut dyn Bridge,
) {
    let (send_requests, mut recv_requests) = mpsc::channel(1);
    // Demux N FIDL connections into a single request stream.
    let forward_requests =
        fuchsia_async::Task::local(connections.for_each_concurrent(None, move |conn| {
            let send_requests = send_requests.clone().sink_map_err(SinkError::Forward);
            async move {
                let res = match conn {
                    IncomingService::OptOut(conn) => {
                        conn.map_ok(IncomingRequest::OptOut)
                            .map_err(SinkError::Read)
                            .forward(send_requests)
                            .await
                    }
                    IncomingService::OptOutAdmin(conn) => {
                        conn.map_ok(IncomingRequest::OptOutAdmin)
                            .map_err(SinkError::Read)
                            .forward(send_requests)
                            .await
                    }
                };
                match res {
                    Ok(()) => {}
                    Err(e @ SinkError::Read(_)) => {
                        let e = anyhow!(e);
                        warn!("Closing request channel: {e:#}");
                    }
                    Err(SinkError::Forward(_)) => {
                        // unreachable. The receive side is only closed after this task finishes.
                    }
                }
            }
        }));
    // Serve that single request stream 1 request at a time.
    while let Some(request) = recv_requests.next().await {
        handle_request(request, storage).await;
    }
    forward_requests.await
}
async fn serve_connections ( connections : impl Stream < Item = IncomingService > + ' static , storage : & mut dyn Bridge , ) { let ( send_requests , mut recv_requests ) = mpsc :: channel ( 1 ) ; // Demux N FIDL connections into a single request stream. let forward_requests = fuchsia_async :: Task :: local ( connections . for_each_concurrent ( None , move | conn | { let send_requests = send_requests . clone ( ) . sink_map_err ( SinkError :: Forward ) ; async move { let res = match conn { IncomingService :: OptOut ( conn ) => { conn . map_ok ( IncomingRequest :: OptOut ) . map_err ( SinkError :: Read ) . forward ( send_requests ) . await } IncomingService :: OptOutAdmin ( conn ) => { conn . map_ok ( IncomingRequest :: OptOutAdmin ) . map_err ( SinkError :: Read ) . forward ( send_requests ) . await } } ; match res { Ok ( ( ) ) => { } Err ( e @ SinkError :: Read ( _ ) ) => { let e = anyhow ! ( e ) ; warn ! ( " " ) ; } Err ( SinkError :: Forward ( _ ) ) => { // unreachable. The receive side is only closed after this task finishes. } } } } ) ) ; // Serve that single request stream 1 request at a time. while let Some ( request ) = recv_requests . next ( ) . await { handle_request ( request , storage ) . await ; } forward_requests . await }
Serve incoming connections using the provided backing `storage`.
Serve incoming connections using the provided backing ` storage ` .
connections
impl Stream<Item = IncomingService> + 'static
storage
&mut dyn Bridge