pub trait TimerCallback:
Send
+ Sync
+ 'static {
// Required method
fn call(&self) -> Pin<Box<dyn Future<Output = ()> + Send>>;
}Expand description
定时器回调 trait (Timer Callback Trait)
实现此 trait 的类型可以作为定时器的回调函数使用。 (Types implementing this trait can be used as timer callbacks)
§示例
use kestrel_timer::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§
Implementors§
impl<F, Fut> TimerCallback for F
为闭包实现 TimerCallback trait (Implement TimerCallback trait for closures) 支持 Fn() -> Future 类型的闭包(可以多次调用,适合周期性任务) (Supports Fn() -> Future closures, can be called multiple times, suitable for periodic tasks)