pub struct Wheel<T>{ /* private fields */ }Expand description
§Time Wheel Proxy
this provide user with easy-use functions to interact with TimeWheel
§example
use gsfw_util::timer::Wheel;
#[tokio::main]
async fn main() {
let now = std::time::Instant::now();
let mut wheel = Wheel::<i32>::new(60, std::time::Duration::from_secs(1), now);
let snapshot = wheel.dispatch(std::time::Duration::from_secs(2), 1).await.unwrap();
let recv_data = wheel.tick().await;
assert_eq!(recv_data.len(), 1);
assert_eq!(recv_data[0].id, snapshot.id);
assert_eq!(recv_data[0].data, Some(1));
assert_eq!(recv_data[0].start, snapshot.start);
assert_eq!(recv_data[0].end, snapshot.end);
}Implementations§
Source§impl<T> WheelProxy<T>
impl<T> WheelProxy<T>
pub fn new(slot: u32, slot_duration: Duration, start: Instant) -> Self
pub fn slot(&self) -> u32
pub fn slot_duration(&self) -> Duration
pub fn round_duration(&self) -> Duration
pub fn round_end(&self) -> Instant
pub async fn dispatch( &mut self, duration: Duration, data: T, ) -> Result<Snapshot, Error<T>>
pub async fn dispatch_until( &mut self, end: Instant, data: T, ) -> Result<Snapshot, Error<T>>
pub async fn cancel(&mut self, id: u64) -> Result<(), Error<T>>
pub async fn accelerate( &mut self, id: u64, acc_duration: Duration, ) -> Result<(), Error<T>>
pub async fn delay( &mut self, id: u64, delay_duration: Duration, ) -> Result<(), Error<T>>
pub async fn trigger(&mut self, id: u64) -> Result<(), Error<T>>
Sourcepub async fn batch_add(
&mut self,
metas: Vec<Meta<T>>,
) -> Result<Vec<Snapshot>, Error<T>>
pub async fn batch_add( &mut self, metas: Vec<Meta<T>>, ) -> Result<Vec<Snapshot>, Error<T>>
batch_add atomic operation. either all metas are added to the wheel, nor none is added. batch_add will first check metas’s id is unique and then check all metas are not overflow or elapse
pub async fn tick(&mut self) -> Vec<Meta<T>>
Trait Implementations§
Source§impl<T> Drop for WheelProxy<T>
impl<T> Drop for WheelProxy<T>
Auto Trait Implementations§
impl<T> Freeze for WheelProxy<T>
impl<T> !RefUnwindSafe for WheelProxy<T>
impl<T> Send for WheelProxy<T>
impl<T> Sync for WheelProxy<T>
impl<T> Unpin for WheelProxy<T>
impl<T> UnsafeUnpin for WheelProxy<T>
impl<T> !UnwindSafe for WheelProxy<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more