8383 ) -> Arc < SubscriptionFunc < X > > {
8484 let _func = Arc :: new ( Mutex :: new ( func) ) ;
8585 self . subscribe_fn ( move |x : Arc < X > | {
86- let _func = _func. clone ( ) ;
87- let func = & mut * _func. lock ( ) . unwrap ( ) ;
88- ( func) ( x) ;
86+ ( _func. lock ( ) . unwrap ( ) ) ( x) ;
8987 } )
9088 }
9189 pub fn unsubscribe ( & mut self , s : Arc < SubscriptionFunc < X > > ) {
@@ -136,7 +134,7 @@ impl<X: Send + Sync + 'static> Observable<X, SubscriptionFunc<X>> for Publisher<
136134 observer. as_ref ( ) . clone ( ) . close_stream ( ) ;
137135 }
138136
139- for ( index, obs) in self . observers . clone ( ) . iter ( ) . enumerate ( ) {
137+ for ( index, obs) in self . observers . iter ( ) . enumerate ( ) {
140138 if obs. get_id ( ) == id {
141139 // println!("delete_observer({});", observer);
142140 self . observers . remove ( index) ;
@@ -145,34 +143,25 @@ impl<X: Send + Sync + 'static> Observable<X, SubscriptionFunc<X>> for Publisher<
145143 }
146144 }
147145 fn notify_observers ( & mut self , val : Arc < X > ) {
148- let _observers = self . observers . clone ( ) ;
149- let observers = Arc :: new ( _observers) ;
146+ let observers = self . observers . clone ( ) ;
150147 let mut _do_sub = Arc :: new ( move || {
151- let mut _observers = observers. clone ( ) ;
152- let observers = Arc :: make_mut ( & mut _observers) ;
153-
154148 for ( _, observer) in observers. iter ( ) . enumerate ( ) {
155149 {
156150 observer. on_next ( val. clone ( ) ) ;
157151 }
158152 }
159153 } ) ;
160154
161- let sub_handler_thread = & mut self . sub_handler ;
162- let mut do_sub_thread_ob = _do_sub. clone ( ) ;
163-
164- match sub_handler_thread {
155+ match & mut self . sub_handler {
165156 Some ( ref mut sub_handler) => {
166- let mut do_sub_thread_sub = _do_sub. clone ( ) ;
167-
168157 sub_handler. lock ( ) . unwrap ( ) . post ( RawFunc :: new ( move || {
169- let sub = Arc :: make_mut ( & mut do_sub_thread_sub ) ;
158+ let sub = Arc :: make_mut ( & mut _do_sub ) ;
170159
171160 ( sub) ( ) ;
172161 } ) ) ;
173162 }
174163 None => {
175- let sub = Arc :: make_mut ( & mut do_sub_thread_ob ) ;
164+ let sub = Arc :: make_mut ( & mut _do_sub ) ;
176165 ( sub) ( ) ;
177166 }
178167 } ;
@@ -195,15 +184,15 @@ async fn test_publisher_stream() {
195184 let mut pub1 = Publisher :: new_with_handlers ( Some ( _h. clone ( ) ) ) ;
196185 //*
197186 let s = pub1. subscribe_as_stream ( Arc :: new ( SubscriptionFunc :: new ( move |x| {
198- println ! ( "{:?}: {:?}" , "SS" , x) ;
187+ println ! ( "test_publisher_stream {:?}: {:?}" , "SS" , x) ;
199188 } ) ) ) ;
200189 // */
201190 {
202191 let h = & mut _h. lock ( ) . unwrap ( ) ;
203192
204- println ! ( "hh2" ) ;
193+ println ! ( "test_publisher_stream hh2" ) ;
205194 h. start ( ) ;
206- println ! ( "hh2 running" ) ;
195+ println ! ( "test_publisher_stream hh2 running" ) ;
207196 }
208197 pub1. publish ( 1 ) ;
209198 pub1. publish ( 2 ) ;
@@ -213,12 +202,12 @@ async fn test_publisher_stream() {
213202 {
214203 let mut result = s. clone ( ) ;
215204 for n in 1 ..5 {
216- println ! ( "{:?}: {:?}" , n, "Before" ) ;
205+ println ! ( "test_publisher_stream {:?}: {:?}" , n, "Before" ) ;
217206 let item = result. next ( ) . await ;
218207 if let Some ( result) = item. clone ( ) {
219208 ( & mut got_list) . push ( result. clone ( ) ) ;
220209 }
221- println ! ( "{:?}: {:?}" , n, item) ;
210+ println ! ( "test_publisher_stream {:?}: {:?}" , n, item) ;
222211 }
223212 // got_list = s.collect::<Vec<_>>().await;
224213 }
@@ -252,6 +241,8 @@ async fn test_publisher_stream() {
252241 } ) ) ;
253242 }
254243
244+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 10 ) ) ;
245+
255246 got_list = s. clone ( ) . collect :: < Vec < _ > > ( ) . await ;
256247 assert_eq ! (
257248 vec![ Arc :: new( 5 ) , Arc :: new( 6 ) , Arc :: new( 7 ) , Arc :: new( 8 ) , ] ,
0 commit comments