pub fn new(port: u16) -> Result<(Self, SkillRegisterStream, SkillRegisterOut), Error> {
        let (in_send, in_recv) = mpsc::channel(20);
        let pending_requests = Arc::new(Mutex::new(HashMap::new()));
        let pending_can_you = Arc::new(Mutex::new(HashMap::new()));
        let barrier = Arc::new(Barrier::new(2));

        let (self_send, mut self_recv) = mpsc::channel(20);
        let barrier2 = barrier.clone();
        let _clnt_thrd = thread::spawn(move || {
            // In Linux we need a second thread to to send to ourselves, otherwise
            // what would be a non-blocking operation, tries to block, which
            // returns an error.
            Runtime::new().unwrap().block_on(async move {
                let ip_address = format!("127.0.0.1:{}", port);
                let client = CoAPClient::new(&ip_address).unwrap();
                barrier2.wait(); // Make sure we are not sending anything before the server is ready

                loop {
                    let (name, data): (String, Vec<u8>) = self_recv.next().await.unwrap();
                    println!("Size: {}", data.len());
                    let resp = client
                        .request_path(
                            &format!("vap/skillRegistry/skills/{}", name),
                            Method::Put,
                            Some(data),
                            None,
                        )
                        .unwrap();
                    assert_eq!(resp.get_status(), &coap_lite::ResponseType::Valid);
                }
            });
        });

        Ok((
            SkillRegister {
                ip_address: format!("127.0.0.1:{}", port),
                in_send,
                pending_requests: pending_requests.clone(),
                pending_can_you: pending_can_you.clone(),
                current_skills: Arc::new(SyncMutex::new(HashMap::new())),
                barrier,
                _clnt_thrd,
                self_send: self_send.clone(),
            },
            SkillRegisterStream { stream_in: in_recv },
            SkillRegisterOut {
                pending_requests,
                self_send,
                pending_can_you,
                next_request: RefCell::new(0),
            },
        ))
    }
/// Creates a new skill register, the skill register is divided into three parts:
/// 1. The skill register task, which will handle everything behind the scenes, you just need to await on run().
/// 2. The skill stream, which will receive all the messages from the skills.
/// 3. The skill out, which you can use to send messages to the skills.
/// # Arguments
/// * `port` - The port for the skill register to listen CoAP messages on.    
Creates a new skill register, the skill register is divided into three parts:
1. The skill register task, which will handle everything behind the scenes, you just need to await on run().
2. The skill stream, which will receive all the messages from the skills.
3. The skill out, which you can use to send messages to the skills.
Creates a new skill register the skill register is divided into three parts : 1 . The skill register task which will handle everything behind the scenes you just need to await on run () . 2 . The skill stream which will receive all the messages from the skills . 3 . The skill out which you can use to send messages to the skills .
pub fn new(port: u16) -> Result<(Self, SkillRegisterStream, SkillRegisterOut), Error> {
        let (in_send, in_recv) = mpsc::channel(20);
        let pending_requests = Arc::new(Mutex::new(HashMap::new()));
        let pending_can_you = Arc::new(Mutex::new(HashMap::new()));
        let barrier = Arc::new(Barrier::new(2));
        let (self_send, mut self_recv) = mpsc::channel(20);
        let barrier2 = barrier.clone();
        let _clnt_thrd = thread::spawn(move || {
            // In Linux we need a second thread to to send to ourselves, otherwise
            // what would be a non-blocking operation, tries to block, which
            // returns an error.
            Runtime::new().unwrap().block_on(async move {
                let ip_address = format!("127.0.0.1:{}", port);
                let client = CoAPClient::new(&ip_address).unwrap();
                barrier2.wait(); // Make sure we are not sending anything before the server is ready
                loop {
                    let (name, data): (String, Vec<u8>) = self_recv.next().await.unwrap();
                    println!("Size: {}", data.len());
                    let resp = client
                        .request_path(
                            &format!("vap/skillRegistry/skills/{}", name),
                            Method::Put,
                            Some(data),
                            None,
                        )
                        .unwrap();
                    assert_eq!(resp.get_status(), &coap_lite::ResponseType::Valid);
                }
            });
        });
        Ok((
            SkillRegister {
                ip_address: format!("127.0.0.1:{}", port),
                in_send,
                pending_requests: pending_requests.clone(),
                pending_can_you: pending_can_you.clone(),
                current_skills: Arc::new(SyncMutex::new(HashMap::new())),
                barrier,
                _clnt_thrd,
                self_send: self_send.clone(),
            },
            SkillRegisterStream { stream_in: in_recv },
            SkillRegisterOut {
                pending_requests,
                self_send,
                pending_can_you,
                next_request: RefCell::new(0),
            },
        ))
    }
pub fn new ( port : u16 ) -> Result < ( Self , SkillRegisterStream , SkillRegisterOut ) , Error > { let ( in_send , in_recv ) = mpsc :: channel ( 20 ) ; let pending_requests = Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ; let pending_can_you = Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ; let barrier = Arc :: new ( Barrier :: new ( 2 ) ) ; let ( self_send , mut self_recv ) = mpsc :: channel ( 20 ) ; let barrier2 = barrier . clone ( ) ; let _clnt_thrd = thread :: spawn ( move | | { // In Linux we need a second thread to to send to ourselves, otherwise // what would be a non-blocking operation, tries to block, which // returns an error. Runtime :: new ( ) . unwrap ( ) . block_on ( async move { let ip_address = format ! ( " " port ) ; let client = CoAPClient :: new ( & ip_address ) . unwrap ( ) ; barrier2 . wait ( ) ; // Make sure we are not sending anything before the server is ready loop { let ( name , data ) : ( String , Vec < u8 > ) = self_recv . next ( ) . await . unwrap ( ) ; println ! ( " " data len ( ) ) ; let resp = client . request_path ( & format ! ( " " name ) , Method :: Put , Some ( data ) , None , ) . unwrap ( ) ; assert_eq ! ( resp get_status ( ) coap_lite ResponseType Valid ) ; } } ) ; } ) ; Ok ( ( SkillRegister { ip_address : format ! ( " " port ) , in_send , pending_requests : pending_requests . clone ( ) , pending_can_you : pending_can_you . clone ( ) , current_skills : Arc :: new ( SyncMutex :: new ( HashMap :: new ( ) ) ) , barrier , _clnt_thrd , self_send : self_send . clone ( ) , } , SkillRegisterStream { stream_in : in_recv } , SkillRegisterOut { pending_requests , self_send , pending_can_you , next_request : RefCell :: new ( 0 ) , } , ) ) }
Creates a new skill register, the skill register is divided into three parts:
1.
Creates a new skill register the skill register is divided into three parts : 1 .
port
u16