@@ -8,7 +8,7 @@ use std::sync::Mutex;
8
8
use std:: thread;
9
9
use std:: time:: Duration ;
10
10
use tokio:: runtime:: Builder ;
11
- use tokio :: sync:: mpsc;
11
+ use std :: sync:: mpsc;
12
12
13
13
#[ derive( Clone , Debug ) ]
14
14
pub struct LuaChannel {
@@ -34,7 +34,7 @@ impl LuaChannel {
34
34
}
35
35
36
36
pub fn mt_string ( & self ) -> String {
37
- format ! ( "Channel: {}" , self . name. clone( ) )
37
+ format ! ( "Channel: {} {} " , self . name. clone( ) , self . id )
38
38
}
39
39
}
40
40
@@ -52,7 +52,7 @@ impl LuaChannelMgr {
52
52
}
53
53
54
54
pub fn new_channel ( & mut self , name : String ) {
55
- let ( sender, receiver) = mpsc:: channel ( 100 ) ;
55
+ let ( sender, receiver) = mpsc:: channel ( ) ;
56
56
let id = self . id_counter ;
57
57
self . id_counter += 1 ;
58
58
let channel = LuaChannel :: new (
@@ -79,11 +79,11 @@ impl UserData for LuaChannel {
79
79
Ok ( this. mt_string ( ) )
80
80
} ) ;
81
81
82
- methods. add_async_method ( "push" , |lua, this, args : mlua:: MultiValue | async move {
82
+ methods. add_method ( "push" , move |lua, this, args : mlua:: MultiValue | {
83
83
let lua_seri_pack = lua. globals ( ) . get :: < LuaFunction > ( "lua_seri_pack" ) ?;
84
84
let ptr = lua_seri_pack. call :: < i64 > ( args) . unwrap ( ) ;
85
85
let sender = this. sender . lock ( ) . unwrap ( ) ;
86
- sender. send ( ptr) . await . unwrap ( ) ;
86
+ sender. send ( ptr) . unwrap ( ) ;
87
87
Ok ( ( ) )
88
88
} ) ;
89
89
@@ -101,9 +101,9 @@ impl UserData for LuaChannel {
101
101
Ok ( returns)
102
102
} ) ;
103
103
104
- methods. add_async_method ( "bpop" , |lua, this, ( ) | async move {
105
- let data = { this. receiver . lock ( ) . unwrap ( ) . recv ( ) . await } ;
106
- if let Some ( data) = data {
104
+ methods. add_method ( "bpop" , move |lua, this, ( ) | {
105
+ let data = this. receiver . lock ( ) . unwrap ( ) . recv ( ) ;
106
+ if let Ok ( data) = data {
107
107
let lua_seri_unpack = lua. globals ( ) . get :: < LuaFunction > ( "lua_seri_unpack" ) ?;
108
108
let returns = lua_seri_unpack. call :: < mlua:: MultiValue > ( data) . unwrap ( ) ;
109
109
return Ok ( returns) ;
0 commit comments