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::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
Implement TimerCallback trait for closures
Supports Fn() -> Future closures, can be called multiple times, suitable for periodic tasks
实现 TimerCallback 特性的类型,支持 Fn() -> Future 闭包,可以多次调用,适合周期性任务