Skip to content

Commit 5b35df3

Browse files
committed
fix deadlock
1 parent 60d68de commit 5b35df3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/bee/lua_thread.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::sync::Mutex;
88
use std::thread;
99
use std::time::Duration;
1010
use tokio::runtime::Builder;
11-
use tokio::sync::mpsc;
11+
use std::sync::mpsc;
1212

1313
#[derive(Clone, Debug)]
1414
pub struct LuaChannel {
@@ -34,7 +34,7 @@ impl LuaChannel {
3434
}
3535

3636
pub fn mt_string(&self) -> String {
37-
format!("Channel: {}", self.name.clone())
37+
format!("Channel: {} {}", self.name.clone(), self.id)
3838
}
3939
}
4040

@@ -52,7 +52,7 @@ impl LuaChannelMgr {
5252
}
5353

5454
pub fn new_channel(&mut self, name: String) {
55-
let (sender, receiver) = mpsc::channel(100);
55+
let (sender, receiver) = mpsc::channel();
5656
let id = self.id_counter;
5757
self.id_counter += 1;
5858
let channel = LuaChannel::new(
@@ -79,11 +79,11 @@ impl UserData for LuaChannel {
7979
Ok(this.mt_string())
8080
});
8181

82-
methods.add_async_method("push", |lua, this, args: mlua::MultiValue| async move {
82+
methods.add_method("push", move|lua, this, args: mlua::MultiValue| {
8383
let lua_seri_pack = lua.globals().get::<LuaFunction>("lua_seri_pack")?;
8484
let ptr = lua_seri_pack.call::<i64>(args).unwrap();
8585
let sender = this.sender.lock().unwrap();
86-
sender.send(ptr).await.unwrap();
86+
sender.send(ptr).unwrap();
8787
Ok(())
8888
});
8989

@@ -101,9 +101,9 @@ impl UserData for LuaChannel {
101101
Ok(returns)
102102
});
103103

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 {
107107
let lua_seri_unpack = lua.globals().get::<LuaFunction>("lua_seri_unpack")?;
108108
let returns = lua_seri_unpack.call::<mlua::MultiValue>(data).unwrap();
109109
return Ok(returns);

0 commit comments

Comments
 (0)