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 timer_fd = Timer::set_timerfd()?;
        let epoll_fd = Timer::create_epollfd(timer_fd)?;

        let handle = Some(thread::spawn(move || {
            loop {
                // Exit thread if there are no listeners
                if txs.lock()?.len() == 0 {
                    // Close file descriptors
                    unsafe { libc::close(timer_fd) };
                    unsafe { libc::close(epoll_fd) };

                    return Ok(());
                }

                // Fire @ 10th sec
                Timer::epoll_wait(timer_fd, epoll_fd)?;

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

                // Iterate through Senders
                txs.lock()?.iter().for_each(|tx| {
                    // Send event to attached Sender
                    if tx.send(from).is_ok() {}
                });
            }
        }));

        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 timer_fd = Timer::set_timerfd()?;
        let epoll_fd = Timer::create_epollfd(timer_fd)?;
        let handle = Some(thread::spawn(move || {
            loop {
                // Exit thread if there are no listeners
                if txs.lock()?.len() == 0 {
                    // Close file descriptors
                    unsafe { libc::close(timer_fd) };
                    unsafe { libc::close(epoll_fd) };
                    return Ok(());
                }
                // Fire @ 10th sec
                Timer::epoll_wait(timer_fd, epoll_fd)?;
                // Get the current time range
                let from = get_time_range(0)?.from;
                // Iterate through Senders
                txs.lock()?.iter().for_each(|tx| {
                    // Send event to attached Sender
                    if tx.send(from).is_ok() {}
                });
            }
        }));
        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 timer_fd = Timer :: set_timerfd ( ) ? ; let epoll_fd = Timer :: create_epollfd ( timer_fd ) ? ; let handle = Some ( thread :: spawn ( move | | { loop { // Exit thread if there are no listeners if txs . lock ( ) ? . len ( ) == 0 { // Close file descriptors unsafe { libc :: close ( timer_fd ) } ; unsafe { libc :: close ( epoll_fd ) } ; return Ok ( ( ) ) ; } // Fire @ 10th sec Timer :: epoll_wait ( timer_fd , epoll_fd ) ? ; // Get the current time range let from = get_time_range ( 0 ) ? . from ; // Iterate through Senders txs . lock ( ) ? . iter ( ) . for_each ( | tx | { // Send event to attached Sender if tx . send ( from ) . is_ok ( ) { } } ) ; } } ) ) ; 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