You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: matchmaker.rs
    path of file: ./repos/muddle-run/libs/client_lib/src/net
    
    the code of the file until where you have to start completion: use crate::{
    net::TcpConnectionStatus,
    websocket::{Message, WebSocketStream},
};
use bevy::log;
use futures::{select, FutureExt, SinkExt, StreamExt, TryStreamExt};
use mr_messages_lib::{deserialize_binary, serialize_binary, MatchmakerMessage, MatchmakerRequest};
use std::time::Duration;
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
use url::Url;

pub struct MatchmakerRequestsHandler {
    pub url: Url,
    pub connection_request_rx: UnboundedReceiver<bool>,
    pub status_tx: UnboundedSender<TcpConnectionStatus>,
    pub matchmaker_message_tx: UnboundedSender<MatchmakerMessage>,
}

impl MatchmakerRequestsHandler {
    pub async fn serve(mut self, matchmaker_request_rx: UnboundedReceiver<MatchmakerRequest>) {
        let mut matchmaker_request_rx = Some(matchmaker_re
    
    pub async fn serve(mut self, matchmaker_request_rx: UnboundedReceiver<MatchmakerRequest>) {
        let mut matchmaker_request_rx = Some(matchmaker_request_rx);
        let mut current_state = false;

        let mut disconnect_request_tx = None;
        let (disconnect_tx, mut disconnect_rx) = tokio::sync::mpsc::unbounded_channel();
        loop {
            let connect = select! {
                connect = self.connection_request_rx.recv().fuse() => connect,
                disconnected_matchmaker_request_rx = disconnect_rx.recv().fuse() => {
                    matchmaker_request_rx = Some(disconnected_matchmaker_request_rx.expect("Disconnect channel closed unexpectedly"));
                    Some(false)
                },
            };
            let connect = match connect {
                Some(connect) => connect,
                None => break,
            };

            if current_state == connect {
                continue;
            }

            if connect {
                log::info!("Connecting to the matchmaker service...");
                let _ = self.status_tx.send(TcpConnectionStatus::Connecting);
                let message_tx = self.matchmaker_message_tx.clone();
                let url = self.url.clone();
                let ws_status_tx = self.status_tx.clone();
                let disconnect_request_channel = tokio::sync::oneshot::channel();
                disconnect_request_tx = Some(disconnect_request_channel.0);
                tokio::task::spawn_local(handle_matchmaker_connection(
                    message_tx,
                    matchmaker_request_rx.take().unwrap(),
                    url,
                    ws_status_tx,
                    disconnect_request_channel.1,
                    disconnect_tx.clone(),
                ));
            } else {
                // If this fails, the connection is already closed.
                if disconnect_request_tx.take().unwrap().send(()).is_ok() {
                    log::info!("Dropping the connection with the matchmaker service...");
                    let _ = self.status_tx.send(TcpConnectionStatus::Disconnected);
                }
                wasm_timer::Delay::new(Duration::from_millis(500))
                    .await
                    .unwrap();
            }

            current_state = connect;
        }
        panic!("Failed to read from a channel (matchmaker connection request)");
    }