1- use std:: panic:: { catch_unwind, RefUnwindSafe } ;
1+ use crossbeam_channel:: { Receiver , RecvTimeoutError , TryRecvError } ;
2+ use std:: panic:: { catch_unwind, UnwindSafe } ;
23use std:: sync:: atomic:: { AtomicBool , Ordering } ;
3- use std:: sync:: mpsc:: { self , Receiver , RecvTimeoutError , TryRecvError } ;
44use std:: sync:: Arc ;
55use std:: sync:: Mutex ;
66use std:: thread;
@@ -98,16 +98,16 @@ pub struct BackgroundHandle<T, S> {
9898impl < T , S > BackgroundHandle < T , S > {
9999 pub fn spawn < K > ( task : K ) -> BackgroundHandle < T , S >
100100 where
101- K : Background < Output = T , Status = S > + RefUnwindSafe + Send + Sync + ' static ,
101+ K : Background < Output = T , Status = S > + UnwindSafe + Send + Sync + ' static ,
102102 T : Send + Sync + ' static ,
103103 S : Send + Sync + Clone + ' static ,
104104 {
105- let ( tx, rx) = mpsc :: channel ( ) ;
105+ let ( tx, rx) = crossbeam_channel :: unbounded ( ) ;
106106 let control = ControlToken :: new ( ) ;
107107 let inner_control = control. clone ( ) ;
108108
109109 let handle = thread:: spawn ( move || {
110- let response = catch_unwind ( || task. run ( & inner_control) ) ;
110+ let response = catch_unwind ( move || task. run ( & inner_control) ) ;
111111 let _ = tx. send ( response) ;
112112 } ) ;
113113
@@ -180,7 +180,7 @@ pub trait Background: Send + Sync {
180180 type Output : Send + Sync ;
181181 type Status : Send + Sync ;
182182
183- fn run ( & self , control : & ControlToken < Self :: Status > ) -> Self :: Output ;
183+ fn run ( self , control : & ControlToken < Self :: Status > ) -> Self :: Output ;
184184}
185185
186186#[ cfg( test) ]
@@ -195,7 +195,7 @@ mod tests {
195195 type Output = Result < u32 , u32 > ;
196196 type Status = u32 ;
197197
198- fn run ( & self , control : & ControlToken < Self :: Status > ) -> Self :: Output {
198+ fn run ( self , control : & ControlToken < Self :: Status > ) -> Self :: Output {
199199 let mut ticks = 0 ;
200200
201201 while ticks < 100 && !control. is_cancelled_with_pause ( ) {
0 commit comments