pub fn fire_oneshot<F>(
due: Duration,
hint: Option<CallbackHint>,
handler: F,
) -> Result<()>Expand description
Schedule an one-shot background task on the default TimerQueue. Note that, unlike other schedule_* functions, this fire_oneshot
requires a 'static lifetime closure.
§Arguments
due: Due time to execute the taskhint: Behavior hint ofhandler, which impacts how the task will be scheduledhandler: The task to be called back
returns: Result<(), TimerError>
§Examples
use native_timer::fire_oneshot;
let flag = Arc::new(AtomicBool::new(false));
let shared_flag = flag.clone();
fire_oneshot(Duration::from_millis(100), None, move || {
let _ = &shared_flag.store(true, Ordering::SeqCst);
}).unwrap();
thread::sleep(Duration::from_millis(200));
assert!(flag.load(Ordering::SeqCst));