pub struct TimerHandle { /* private fields */ }
Expand description

Timer handles are used to schedule callbacks to be called in the future.

Implementations§

source§

impl TimerHandle

source

pub fn new(loop: &Loop) -> Result<TimerHandle>

Create and initialize a new timer handle

source

pub fn start<CB: Into<TimerCB<'static>>>( &mut self, timeout: u64, repeat: u64, cb: CB ) -> Result<()>

Start the timer. timeout and repeat are in milliseconds.

If timeout is zero, the callback fires on the next event loop iteration. If repeat is non-zero, the callback fires first after timeout milliseconds and then repeatedly after repeat milliseconds.

Note: Does not update the event loop’s concept of “now”. See Loop.update_time() for more information.

If the timer is already active, it is simply updated.

source

pub fn stop(&mut self) -> Result<()>

Stop the timer, the callback will not be called anymore.

source

pub fn again(&mut self) -> Result<()>

Stop the timer, and if it is repeating restart it using the repeat value as the timeout. If the timer has never been started before it returns EINVAL.

source

pub fn set_repeat(&mut self, repeat: u64)

Set the repeat interval value in milliseconds. The timer will be scheduled to run on the given interval, regardless of the callback execution duration, and will follow normal timer semantics in the case of a time-slice overrun.

For example, if a 50ms repeating timer first runs for 17ms, it will be scheduled to run again 33ms later. If other tasks consume more than the 33ms following the first timer callback, then the callback will run as soon as possible.

Note: If the repeat value is set from a timer callback it does not immediately take effect. If the timer was non-repeating before, it will have been stopped. If it was repeating, then the old repeat value will have been used to schedule the next timeout.

source

pub fn get_repeat(&self) -> u64

Get the timer repeat value.

source

pub fn due_in(&self) -> u64

Get the timer due value or 0 if it has expired. The time is relative to now().

Trait Implementations§

source§

impl Clone for TimerHandle

source§

fn clone(&self) -> TimerHandle

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl From<TimerHandle> for Handle

source§

fn from(timer: TimerHandle) -> Handle

Converts to this type from the input type.
source§

impl HandleTrait for TimerHandle

source§

fn is_active(&self) -> bool

Returns non-zero if the handle is active, zero if it’s inactive. What “active” means depends on the type of handle: Read more
source§

fn is_closing(&self) -> bool

Returns non-zero if the handle is closing or closed, zero otherwise. Read more
source§

fn close<CB: Into<CloseCB<'static>>>(&mut self, cb: CB)

Request handle to be closed. close_cb will be called asynchronously after this call. This MUST be called on each handle before memory is released. Moreover, the memory can only be released in close_cb or after it has returned. Read more
source§

fn ref(&mut self)

Reference the given handle. References are idempotent, that is, if a handle is already referenced calling this function again will have no effect.
source§

fn unref(&mut self)

Un-reference the given handle. References are idempotent, that is, if a handle is not referenced calling this function again will have no effect.
source§

fn has_ref(&self) -> bool

Returns true if the handle referenced, zero otherwise.
source§

fn send_buffer_size(&mut self, value: i32) -> Result<i32>

Gets or sets the size of the send buffer that the operating system uses for the socket. Read more
source§

fn recv_buffer_size(&mut self, value: i32) -> Result<i32>

Gets or sets the size of the receive buffer that the operating system uses for the socket. Read more
source§

fn get_fileno(&self) -> Result<OsFile>

Gets the platform dependent file descriptor equivalent. Read more
source§

fn get_loop(&self) -> Loop

Returns the Loop associated with this handle.
source§

fn get_type(&self) -> HandleType

Returns the type of the handle.
source§

impl ToHandle for TimerHandle

source§

impl TryFrom<Handle> for TimerHandle

§

type Error = ConversionError

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

fn try_from(handle: Handle) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for TimerHandle

Auto Trait Implementations§

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, 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

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

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

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

§

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>,

§

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.