TimerCallback

Trait TimerCallback 

Source
pub trait TimerCallback:
    Send
    + Sync
    + 'static {
    // Required method
    fn call(&self) -> Pin<Box<dyn Future<Output = ()> + Send>>;
}
Expand description

Timer Callback Trait

Types implementing this trait can be used as timer callbacks.

可实现此特性的类型可以作为定时器回调函数。

§Examples (示例)

use kestrel_timer::task::TimerCallback;
use std::future::Future;
use std::pin::Pin;
 
struct MyCallback;
 
impl TimerCallback for MyCallback {
    fn call(&self) -> Pin<Box<dyn Future<Output = ()> + Send>> {
        Box::pin(async {
            println!("Timer callback executed!");
        })
    }
}

Required Methods§

Source

fn call(&self) -> Pin<Box<dyn Future<Output = ()> + Send>>

Execute callback, returns a Future

执行回调函数,返回一个 Future

Implementors§

Source§

impl<F, Fut> TimerCallback for F
where F: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + 'static,

Implement TimerCallback trait for closures

Supports Fn() -> Future closures, can be called multiple times, suitable for periodic tasks

实现 TimerCallback 特性的类型,支持 Fn() -> Future 闭包,可以多次调用,适合周期性任务