@@ -27,20 +27,26 @@ impl Default for Actor {
2727impl Actor {
2828 pub fn new ( ) -> Actor {
2929 let actor: Actor = Default :: default ( ) ;
30- actor. start ( ) ;
30+ actor. start_handler ( ) ;
3131 actor
3232 }
3333 pub fn new_with_handler ( handler : Option < Arc < Mutex < HandlerThread > > > ) -> Actor {
3434 let mut actor: Actor = Default :: default ( ) ;
3535 actor. handler = handler;
36- actor. start ( ) ;
36+ actor. start_handler ( ) ;
3737 actor
3838 }
3939
4040 pub fn lua ( & self ) -> Arc < Mutex < Lua > > {
4141 self . lua . clone ( )
4242 }
43- fn start ( & self ) {
43+ pub fn stop_handler ( & self ) {
44+ match self . handler {
45+ Some ( ref _h) => _h. lock ( ) . unwrap ( ) . stop ( ) ,
46+ None => { } ,
47+ }
48+ }
49+ fn start_handler ( & self ) {
4450 match self . handler {
4551 Some ( ref _h) => _h. lock ( ) . unwrap ( ) . start ( ) ,
4652 None => { } ,
@@ -155,6 +161,21 @@ impl Actor {
155161 }
156162 }
157163 }
164+ pub fn exec_nowait ( & self , source : & ' static str , name : Option < & ' static str > ) -> Result < ( ) , Error > {
165+ match self . handler . clone ( ) {
166+ Some ( _handler) => {
167+ let lua = self . lua . clone ( ) ;
168+ _handler. lock ( ) . unwrap ( ) . post ( RawFunc :: new ( move ||{
169+ let _ = Self :: _exec ( lua. clone ( ) , source. clone ( ) , name. clone ( ) ) ;
170+ } ) ) ;
171+ Ok ( ( ) )
172+ } ,
173+ None => {
174+ Self :: _exec ( self . lua . clone ( ) , source, name) ?;
175+ Ok ( ( ) )
176+ }
177+ }
178+ }
158179 fn _exec ( lua : Arc < Mutex < Lua > > , source : & str , name : Option < & str > ) -> Result < LuaMessage , Error > {
159180 let vm = lua. lock ( ) . unwrap ( ) ;
160181 Ok ( vm. exec ( source, name) ?)
0 commit comments