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);

        // Spawn a Thread
        let handle = Some(thread::spawn(move || {
            // Get remaining time for 10th second fire event
            let rem = get_time_range(0)?.rem;

            // Sleep for rem seconds
            thread::sleep(Duration::from_secs(rem));

            loop {
                // Exit thread if there are no listeners
                if txs.lock()?.len() == 0 {
                    return Ok(());
                }

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

                // Iterate through Senders
                txs.lock()?.iter().for_each(|tx| {
                    // Send event to attached Sender
                    let _res = tx.send(current);
                });

                // Sleep for 10s
                thread::sleep(Duration::from_millis(10000));
            }
        }));

        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);
        // Spawn a Thread
        let handle = Some(thread::spawn(move || {
            // Get remaining time for 10th second fire event
            let rem = get_time_range(0)?.rem;
            // Sleep for rem seconds
            thread::sleep(Duration::from_secs(rem));
            loop {
                // Exit thread if there are no listeners
                if txs.lock()?.len() == 0 {
                    return Ok(());
                }
                // Get current time
                let current = get_time_range(0)?.from;
                // Iterate through Senders
                txs.lock()?.iter().for_each(|tx| {
                    // Send event to attached Sender
                    let _res = tx.send(current);
                });
                // Sleep for 10s
                thread::sleep(Duration::from_millis(10000));
            }
        }));
        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 ) ; // Spawn a Thread let handle = Some ( thread :: spawn ( move | | { // Get remaining time for 10th second fire event let rem = get_time_range ( 0 ) ? . rem ; // Sleep for rem seconds thread :: sleep ( Duration :: from_secs ( rem ) ) ; loop { // Exit thread if there are no listeners if txs . lock ( ) ? . len ( ) == 0 { return Ok ( ( ) ) ; } // Get current time let current = get_time_range ( 0 ) ? . from ; // Iterate through Senders txs . lock ( ) ? . iter ( ) . for_each ( | tx | { // Send event to attached Sender let _res = tx . send ( current ) ; } ) ; // Sleep for 10s thread :: sleep ( Duration :: from_millis ( 10000 ) ) ; } } ) ) ; 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