Clock

Struct Clock 

Source
pub struct Clock(/* private fields */);

Implementations§

Source§

impl Clock

Source

pub fn new(tb: Option<Box<NonBlockTickBridge>>) -> Option<Self>

Creates a new Clock instance collocated with application thread. It is recommended to create collocated Clock for message-based applications, especially when each application instance is anchored to a dedicated thread. This ensures that the clock is synchronized with the application thread, allowing all relevant timers to be handled within the same thread for optimal performance.

Panics if too many instances are created. The instance will persist until the process is closed. Implements the Copy trait, maintaining only one real instance.

§Arguments
  • tb: Tick bridge, a proxy to pass the tick to the clock instance when the clock is collocated with application thread, otherwise, None.
§Returns

The newly created Clock instance.

Source

pub fn take_thread_handle() -> Option<JoinHandle<()>>

Takes the thread handle of the Timer module for graceful shutdown.

§Returns

The thread handle for the Timer module shutdown.

Source

pub fn terminate_for_process_exit()

Terminates the Timer module.

Source

pub fn on_tick(self, tick: Tick) -> AnyResult<()>

In case of clock instance is collocated with application thread, at the end of the path of relaying Tick, the application shall invoke clock.on_tick() to send the event to relevant instance. See the sample for TickBridge.

Source

pub fn len(self) -> isize

Retrieves the number of timer instances residing on the Clock.

§Returns

The count of timer instances.

Source

pub fn now(self) -> u64

Retrieves the current tick of the Clock.

§Returns

The current tick.

Trait Implementations§

Source§

impl Clone for Clock

Source§

fn clone(&self) -> Clock

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Clock

Auto Trait Implementations§

§

impl Freeze for Clock

§

impl RefUnwindSafe for Clock

§

impl Send for Clock

§

impl Sync for Clock

§

impl Unpin for Clock

§

impl UnwindSafe for Clock

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.