Skip to main content

Wheel

Struct Wheel 

Source
pub struct Wheel<T>
where T: Debug + Send,
{ /* 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>
where T: Send + Debug + 'static,

Source

pub fn new(slot: u32, slot_duration: Duration, start: Instant) -> Self

Source

pub fn slot(&self) -> u32

Source

pub fn slot_duration(&self) -> Duration

Source

pub fn round_duration(&self) -> Duration

Source

pub fn round_end(&self) -> Instant

Source

pub async fn dispatch( &mut self, duration: Duration, data: T, ) -> Result<Snapshot, Error<T>>

Source

pub async fn dispatch_until( &mut self, end: Instant, data: T, ) -> Result<Snapshot, Error<T>>

Source

pub async fn cancel(&mut self, id: u64) -> Result<(), Error<T>>

Source

pub async fn accelerate( &mut self, id: u64, acc_duration: Duration, ) -> Result<(), Error<T>>

Source

pub async fn delay( &mut self, id: u64, delay_duration: Duration, ) -> Result<(), Error<T>>

Source

pub async fn trigger(&mut self, id: u64) -> Result<(), Error<T>>

Source

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

Source

pub async fn tick(&mut self) -> Vec<Meta<T>>

Trait Implementations§

Source§

impl<T> Drop for WheelProxy<T>
where T: Debug + Send,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more