File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -23,11 +23,23 @@ impl Timer {
2323 self
2424 }
2525
26+ /// Attach an mpsc::Sender to Timer
27+ ///
28+ /// Timer will dispatch an event with the timestamp of the current instant,
29+ /// every 10th second to all attached senders
2630 pub fn attach_listener ( & mut self , tx : Sender < u64 > ) -> Result < ( ) > {
31+ // Push Sender to a Vector of Sender(s)
32+ let txs = Arc :: clone ( & self . txs ) ;
33+ txs. lock ( ) ?. push ( tx) ;
34+
2735 Ok ( ( ) )
2836 }
2937
38+ /// Clear the listeners (txs) from Timer. This will shutdown the Timer thread
3039 pub fn drop_listeners ( & mut self ) -> Result < ( ) > {
40+ let txs = Arc :: clone ( & self . txs ) ;
41+ txs. lock ( ) ?. clear ( ) ;
42+
3143 Ok ( ( ) )
3244 }
3345}
Original file line number Diff line number Diff line change @@ -23,11 +23,23 @@ impl Timer {
2323 self
2424 }
2525
26+ /// Attach an mpsc::Sender to Timer
27+ ///
28+ /// Timer will dispatch an event with the timestamp of the current instant,
29+ /// every 10th second to all attached senders
2630 pub fn attach_listener ( & mut self , tx : Sender < u64 > ) -> Result < ( ) > {
31+ // Push Sender to a Vector of Sender(s)
32+ let txs = Arc :: clone ( & self . txs ) ;
33+ txs. lock ( ) ?. push ( tx) ;
34+
2735 Ok ( ( ) )
2836 }
2937
38+ /// Clear the listeners (txs) from Timer. This will shutdown the Timer thread
3039 pub fn drop_listeners ( & mut self ) -> Result < ( ) > {
40+ let txs = Arc :: clone ( & self . txs ) ;
41+ txs. lock ( ) ?. clear ( ) ;
42+
3143 Ok ( ( ) )
3244 }
3345}
You can’t perform that action at this time.
0 commit comments