pub fn initialize(self) -> Result<Self> {
        let txs = Arc::clone(&self.txs);

        // Add Default tx
        let (tx, _rx): (Sender<u64>, Receiver<u64>) = channel();
        txs.lock()?.push(tx);

        let kqueue = kqueue()?;

        let handle = Some(thread::spawn(move || {
            // Wait for initial expiration
            let initial_event = Timer::register_initial_expiration(kqueue)?;
            Timer::wait_event(kqueue, [initial_event].as_mut_ptr())?;

            // Register loop event
            let loop_event = Timer::register_loop_expiration(kqueue)?;

            // Loop 10s
            loop {
                // Exit thread if there are no listeners
                if txs.lock()?.len() == 0 {
                    // TODO: should close file descriptors?
                    return Ok(());
                }


                // Get current time
                let from = get_time_range(0)?.from;

                // Iterate through Senders
                txs.lock()?.iter().for_each(|tx| {
                    // Send event to attached Sender
                    match tx.send(from) {
                        Ok(_) => {}
                        Err(_) => {}
                    }
                });

                // Wait 10s
                Timer::wait_event(kqueue, [loop_event].as_mut_ptr())?;
            }
        }));

        Ok(Self { handle, ..self })
    }
/// Initialize Timer and run a thread to send events to attached listeners
Initialize Timer and run a thread to send events to attached listeners
Initialize Timer and run a thread to send events to attached listeners
pub fn initialize(self) -> Result<Self> {
        let txs = Arc::clone(&self.txs);
        // Add Default tx
        let (tx, _rx): (Sender<u64>, Receiver<u64>) = channel();
        txs.lock()?.push(tx);
        let kqueue = kqueue()?;
        let handle = Some(thread::spawn(move || {
            // Wait for initial expiration
            let initial_event = Timer::register_initial_expiration(kqueue)?;
            Timer::wait_event(kqueue, [initial_event].as_mut_ptr())?;
            // Register loop event
            let loop_event = Timer::register_loop_expiration(kqueue)?;
            // Loop 10s
            loop {
                // Exit thread if there are no listeners
                if txs.lock()?.len() == 0 {
                    // TODO: should close file descriptors?
                    return Ok(());
                }
                // Get current time
                let from = get_time_range(0)?.from;
                // Iterate through Senders
                txs.lock()?.iter().for_each(|tx| {
                    // Send event to attached Sender
                    match tx.send(from) {
                        Ok(_) => {}
                        Err(_) => {}
                    }
                });
                // Wait 10s
                Timer::wait_event(kqueue, [loop_event].as_mut_ptr())?;
            }
        }));
        Ok(Self { handle, ..self })
    }
pub fn initialize ( self ) -> Result < Self > { let txs = Arc :: clone ( & self . txs ) ; // Add Default tx let ( tx , _rx ) : ( Sender < u64 > , Receiver < u64 > ) = channel ( ) ; txs . lock ( ) ? . push ( tx ) ; let kqueue = kqueue ( ) ? ; let handle = Some ( thread :: spawn ( move | | { // Wait for initial expiration let initial_event = Timer :: register_initial_expiration ( kqueue ) ? ; Timer :: wait_event ( kqueue , [ initial_event ] . as_mut_ptr ( ) ) ? ; // Register loop event let loop_event = Timer :: register_loop_expiration ( kqueue ) ? ; // Loop 10s loop { // Exit thread if there are no listeners if txs . lock ( ) ? . len ( ) == 0 { // TODO: should close file descriptors? return Ok ( ( ) ) ; } // Get current time let from = get_time_range ( 0 ) ? . from ; // Iterate through Senders txs . lock ( ) ? . iter ( ) . for_each ( | tx | { // Send event to attached Sender match tx . send ( from ) { Ok ( _ ) => { } Err ( _ ) => { } } } ) ; // Wait 10s Timer :: wait_event ( kqueue , [ loop_event ] . as_mut_ptr ( ) ) ? ; } } ) ) ; Ok ( Self { handle , .. self } ) }
Initialize Timer and run a thread to send events to attached listeners
Initialize Timer and run a thread to send events to attached listeners
self
self