Skip to content

Commit 1fb24e4

Browse files
committed
Use WillAsync as the waiting base
1 parent c9406b3 commit 1fb24e4

2 files changed

Lines changed: 11 additions & 22 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lua_actor"
3-
version = "0.1.14"
3+
version = "0.1.15"
44
license = "MIT"
55
authors = ["JunYi JohnTeee Lee <johnteee@gmail.com>"]
66
include = ["src/**/*.rs", "Cargo.toml"]

src/actor.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::sync::{Arc, Mutex};
22

33
use fp_rust::{
4-
common::RawFunc,
4+
common::{RawFunc, SubscriptionFunc},
55
handler::{Handler, HandlerThread},
6-
sync::CountDownLatch,
6+
sync::{CountDownLatch, Will, WillAsync},
77
};
88
use message::LuaMessage;
9-
use rlua::{Error, Error::RuntimeError, FromLuaMulti, Function, Lua, ToLuaMulti};
9+
use rlua::{Error, FromLuaMulti, Function, Lua, ToLuaMulti};
1010

1111
#[derive(Clone)]
1212
pub struct Actor {
@@ -70,29 +70,18 @@ impl Actor {
7070
) -> Result<LuaMessage, Error> {
7171
let func = Arc::new(Mutex::new(func));
7272

73-
let _result: Arc<Mutex<Result<LuaMessage, Error>>> =
74-
Arc::new(Mutex::new(Err(RuntimeError(String::from("")))));
75-
let result: Arc<Mutex<Result<LuaMessage, Error>>> = _result.clone();
76-
7773
let done_latch = CountDownLatch::new(1);
78-
7974
let done_latch2 = done_latch.clone();
80-
_handler.lock().unwrap().post(RawFunc::new(move || {
81-
{
82-
(*result.lock().unwrap()) = (func.lock().unwrap().clone())();
83-
}
84-
done_latch2.countdown();
85-
}));
8675

76+
let mut will =
77+
WillAsync::new_with_handler(move || (func.lock().unwrap().clone())(), _handler.clone());
78+
will.add_callback(Arc::new(Mutex::new(SubscriptionFunc::new(move |_| {
79+
done_latch2.countdown();
80+
}))));
81+
will.start();
8782
done_latch.wait();
8883

89-
{
90-
let _result = &*_result.lock().unwrap();
91-
match _result {
92-
Ok(_result) => Ok(_result.clone()),
93-
Err(_err) => Err(_err.clone()),
94-
}
95-
}
84+
will.result().unwrap()
9685
}
9786

9887
pub fn set_global(&self, key: &'static str, value: LuaMessage) -> Result<(), Error> {

0 commit comments

Comments
 (0)