Skip to main content

TimerHandle

Struct TimerHandle 

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

Handle to a scheduled timer with RAII cancellation.

When dropped, the handle automatically cancels the timer if it hasn’t fired yet. This follows the RAII pattern for resource management.

§Example

use reovim_kernel::api::v1::*;
use std::time::Duration;

let mut runtime = Runtime::new();
runtime.boot();

{
    // Timer is scheduled
    let handle = runtime.schedule_delayed(Duration::from_secs(10), || {
        println!("This won't print");
    });
    // handle dropped here - timer is cancelled
}

// Timer was cancelled, won't fire

§Manual Cancellation

You can also explicitly cancel via Runtime::cancel_timer:

use reovim_kernel::api::v1::*;
use std::time::Duration;

let mut runtime = Runtime::new();
runtime.boot();

let handle = runtime.schedule_delayed(Duration::from_secs(10), || {});
let id = handle.id();

// Explicit cancellation
std::mem::forget(handle); // Prevent drop cancellation
let was_pending = runtime.cancel_timer(id);

Implementations§

Source§

impl TimerHandle

Source

pub const fn id(&self) -> TimerId

Get the timer’s unique identifier.

Source

pub const fn is_failed(&self) -> bool

Check if this handle represents a failed scheduling attempt.

Returns true if the timer was not actually scheduled (e.g., due to hitting the max_timers limit).

Source

pub fn detach(self) -> TimerId

Prevent automatic cancellation on drop.

After calling this, dropping the handle will NOT cancel the timer. Use this when you want the timer to fire regardless of handle lifetime.

Returns the timer ID for manual cancellation if needed later.

Trait Implementations§

Source§

impl Debug for TimerHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for TimerHandle

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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