@@ -21,10 +21,13 @@ enum PromiseState<T> {
2121 Rejected ( String ) ,
2222}
2323
24+ type ThenCallbackRef < T > = RefCell < Option < Box < dyn FnOnce ( T ) > > > ;
25+ type CatchCallbackRef = RefCell < Option < Box < dyn FnOnce ( String ) > > > ;
26+
2427pub struct Promise < T > {
2528 state : RefCell < PromiseState < T > > ,
26- then_callback : RefCell < Option < Box < dyn FnOnce ( T ) > > > ,
27- catch_callback : RefCell < Option < Box < dyn FnOnce ( String ) > > > ,
29+ then_callback : ThenCallbackRef < T > ,
30+ catch_callback : CatchCallbackRef ,
2831}
2932
3033impl < T > Promise < T >
@@ -202,7 +205,7 @@ mod tests {
202205 } ) ;
203206
204207 promise. fulfill ( 42 ) ;
205- assert_eq ! ( true , touched. take( ) )
208+ assert ! ( touched. take( ) )
206209 }
207210
208211 #[ test]
@@ -217,7 +220,7 @@ mod tests {
217220 } ) ;
218221
219222 promise. reject ( "Error" . to_string ( ) ) ;
220- assert_eq ! ( true , touched. take( ) )
223+ assert ! ( touched. take( ) )
221224 }
222225
223226 #[ test]
@@ -237,7 +240,7 @@ mod tests {
237240 } ) ;
238241
239242 promise. fulfill ( 10 ) ;
240- assert_eq ! ( true , touched. take( ) )
243+ assert ! ( touched. take( ) )
241244 }
242245
243246 #[ test]
@@ -264,7 +267,7 @@ mod tests {
264267 panic ! ( "Should not reach here" ) ;
265268 } ) ;
266269
267- assert_eq ! ( true , touched. take( ) )
270+ assert ! ( touched. take( ) )
268271 }
269272
270273 #[ test]
@@ -289,7 +292,7 @@ mod tests {
289292 * touched_clone. borrow_mut ( ) = true ;
290293 } ) ;
291294
292- assert_eq ! ( true , touched. take( ) )
295+ assert ! ( touched. take( ) )
293296 }
294297
295298 #[ test]
@@ -314,7 +317,7 @@ mod tests {
314317 * touched_clone. borrow_mut ( ) = true ;
315318 } ) ;
316319
317- assert_eq ! ( true , touched. take( ) )
320+ assert ! ( touched. take( ) )
318321 }
319322
320323 #[ test]
@@ -333,6 +336,6 @@ mod tests {
333336 panic ! ( "Should not reach here" ) ;
334337 } ) ;
335338
336- assert_eq ! ( true , touched. take( ) )
339+ assert ! ( touched. take( ) )
337340 }
338341}
0 commit comments