fire_oneshot

Function fire_oneshot 

Source
pub fn fire_oneshot<F>(
    due: Duration,
    hint: Option<CallbackHint>,
    handler: F,
) -> Result<()>
where F: FnOnce() + Send + 'static,
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 task
  • hint: Behavior hint of handler, which impacts how the task will be scheduled
  • handler: 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));