This commit is contained in:
aozhiwei 2023-10-08 09:03:07 +08:00
parent 7e0ba5ccd1
commit 60265ba68d

View File

@ -27,7 +27,7 @@ struct TimerList {
expire_time: i32,
expires: i64,
//cb: fn (i32, Option<Vec<Rc::<dyn Any>>>),
cb: Option<fn (i32, Option<Vec<Rc::<dyn Any>>>)>,
}
pub struct Timer {
@ -76,7 +76,14 @@ impl Timer {
}
fn new_timer_list(&mut self) -> Rc::<RefCell::<TimerList>> {
let p = Rc::new(RefCell::new(TimerList{
let mut p: Rc::<RefCell::<TimerList>>;
if self.free_timer_list.borrow().empty() {
p = self.free_timer_list.borrow().first_entry().upgrade().unwrap();
if Rc::weak_count(&p.borrow().wp) > 0 {
p.borrow_mut().wp = Rc::new(p.borrow().holder.clone());
}
} else {
p = Rc::new(RefCell::new(TimerList{
holder: Default::default(),
wp: Default::default(),
timer_entry: Default::default(),
@ -84,8 +91,9 @@ impl Timer {
timer_type: 0,
expire_time: 0,
expires: 0,
//cb: Default::default(),
cb: None,
}));
}
return p;
}
@ -94,25 +102,12 @@ impl Timer {
}
pub fn set_timeout(&mut self,
expire_time: i32,
cb: fn (i32, Option<Vec<Rc::<dyn Any>>>)) {
}
pub fn set_timeout_ex(&mut self,
expire_time: i32,
cb: fn (i32, Option<Vec<Rc::<dyn Any>>>),
attacher: Rc::<RefCell::<TimerAttacher>>) {
}
pub fn set_timeout_wp(&mut self,
expire_time: i32,
cb: fn (i32, Option<Vec<Rc::<dyn Any>>>)) -> TimerWp {
return TimerWp::new();
}
pub fn set_timeout_wp_ex(&mut self,
pub fn set_timeout_ex(&mut self,
expire_time: i32,
cb: fn (i32, Option<Vec<Rc::<dyn Any>>>),
attacher: Rc::<RefCell::<TimerAttacher>>) -> TimerWp {