File tree Expand file tree Collapse file tree 1 file changed +15
-13
lines changed Expand file tree Collapse file tree 1 file changed +15
-13
lines changed Original file line number Diff line number Diff line change 1- use std:: { collections:: LinkedList , rc:: Rc } ;
1+ use std:: { collections:: LinkedList , rc:: Rc , time :: Duration } ;
22
33use crossbeam_channel:: { unbounded, TryRecvError } ;
44use mlua:: Lua ;
@@ -81,32 +81,34 @@ fn worker_f(args: Box<WorkerArgs>) -> i32 {
8181 rx,
8282 fiber_standby_timeout,
8383 } = * args;
84+ let fiber_standby_timeout = Duration :: from_secs_f64 ( fiber_standby_timeout) ;
8485
8586 let thread_func = lua
8687 . create_function ( move |lua, _: ( ) | {
8788 loop {
8889 match rx. try_recv ( ) {
89- Ok ( task) => task ( lua) ,
90- Err ( TryRecvError :: Disconnected ) => return Ok ( ( ) ) ,
90+ Ok ( task) => match task ( lua) {
91+ Ok ( ( ) ) => ( ) ,
92+ Err ( ChannelError :: TXChannelClosed ) => continue ,
93+ Err ( err) => break Err ( mlua:: Error :: external ( err) ) ,
94+ } ,
95+ Err ( TryRecvError :: Disconnected ) => break Ok ( ( ) ) ,
9196 Err ( TryRecvError :: Empty ) => {
92- let signaled = cond. wait_timeout ( std:: time:: Duration :: from_secs_f64 (
93- fiber_standby_timeout,
94- ) ) ;
97+ let signaled = cond. wait_timeout ( fiber_standby_timeout) ;
9598 // if !signaled {
9699 // // kill fiber
97- // return Ok(());
100+ // break Ok(());
98101 // }
99- Ok ( ( ) )
100102 }
101103 }
102- . unwrap ( ) ;
103104 }
104105 } )
105- . unwrap ( ) ; // TODO: fix TXChannelClosed (oneshot receiver was dropped)
106+ . unwrap ( ) ;
106107 let thread = lua. create_thread ( thread_func) . unwrap ( ) ;
107- let _: ( ) = thread. resume ( ( ) ) . unwrap ( ) ;
108-
109- 0
108+ match thread. resume ( ( ) ) {
109+ Ok ( ( ) ) => 0 ,
110+ Err ( _) => -1 ,
111+ }
110112}
111113
112114pub ( crate ) struct FiberPool < ' a > {
You can’t perform that action at this time.
0 commit comments