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, expire_time: i32,
expires: i64, expires: i64,
//cb: fn (i32, Option<Vec<Rc::<dyn Any>>>), cb: Option<fn (i32, Option<Vec<Rc::<dyn Any>>>)>,
} }
pub struct Timer { pub struct Timer {
@ -76,16 +76,24 @@ impl Timer {
} }
fn new_timer_list(&mut self) -> Rc::<RefCell::<TimerList>> { fn new_timer_list(&mut self) -> Rc::<RefCell::<TimerList>> {
let p = Rc::new(RefCell::new(TimerList{ let mut p: Rc::<RefCell::<TimerList>>;
holder: Default::default(), if self.free_timer_list.borrow().empty() {
wp: Default::default(), p = self.free_timer_list.borrow().first_entry().upgrade().unwrap();
timer_entry: Default::default(), if Rc::weak_count(&p.borrow().wp) > 0 {
attach_entry: Default::default(), p.borrow_mut().wp = Rc::new(p.borrow().holder.clone());
timer_type: 0, }
expire_time: 0, } else {
expires: 0, p = Rc::new(RefCell::new(TimerList{
//cb: Default::default(), holder: Default::default(),
})); wp: Default::default(),
timer_entry: Default::default(),
attach_entry: Default::default(),
timer_type: 0,
expire_time: 0,
expires: 0,
cb: None,
}));
}
return p; return p;
} }
@ -95,27 +103,14 @@ impl Timer {
pub fn set_timeout(&mut self, pub fn set_timeout(&mut self,
expire_time: i32, expire_time: i32,
cb: fn (i32, Option<Vec<Rc::<dyn Any>>>)) { cb: fn (i32, Option<Vec<Rc::<dyn Any>>>)) -> TimerWp {
return TimerWp::new();
} }
pub fn set_timeout_ex(&mut self, pub fn set_timeout_ex(&mut self,
expire_time: i32, expire_time: i32,
cb: fn (i32, Option<Vec<Rc::<dyn Any>>>), cb: fn (i32, Option<Vec<Rc::<dyn Any>>>),
attacher: Rc::<RefCell::<TimerAttacher>>) { attacher: Rc::<RefCell::<TimerAttacher>>) -> TimerWp {
}
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,
expire_time: i32,
cb: fn (i32, Option<Vec<Rc::<dyn Any>>>),
attacher: Rc::<RefCell::<TimerAttacher>>) -> TimerWp {
return TimerWp::new(); return TimerWp::new();
} }